Ruby 报错 Zlib::BufError (buffer error) ,求救!!!!!

wangping · June 11, 2015 · Last by chenge replied at June 12, 2015 · 4437 hits

问题描述: 用https://dn-ikcrm-files-dev.qbox.me/attachments/files/9/issues.csv 会报错:Zlib::BufError (buffer error)。 其他的不会。

代码如下,大神们可以 try 一下。

 http_download_with_words('https://dn-ikcrm-files-dev.qbox.me/attachments/files/9/issues.csv', 'temp.csv')
def http_download_with_words(uri, filename)
    bytes_total = nil
    binding.pry
    uri.open(
        read_timeout: 500,
        :content_length_proc => lambda{|content_length|
          bytes_total = content_length},
        :progress_proc => lambda{|bytes_transferred|
          if bytes_total
            # Print progress
            print("\r#{bytes_transferred}/#{bytes_total}")
          else
            # We don’t know how much we get, so just print number
            # of transferred bytes
            print("\r#{bytes_transferred} (total size unknown)")
          end
        }
    ) do |file|
      open filename, 'wb' do |io|
        file.each_line do |line|
          io.write line
        end
      end
    end
  end

自己想了一个解决方案:

file.write(curl #{attachment.file.url}) it is work!

有人知道为啥吗?

自己翻墙谷歌搜索下 Zlib::BufError 吧,SatckOverflow 上有不少英文的。这个比较冷门,熟悉的人不多。

#2 楼 @chenge 翻了很久,没找到解决方案

https://ruby-china.org/topics/14963这里有一个类似的。 zlib 是做压缩的。

You need to Sign in before reply, if you don't have an account, please Sign up first.