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

wangping · 2015年06月11日 · 最后由 chenge 回复于 2015年06月12日 · 4435 次阅读

问题描述: 用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 是做压缩的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号