0

我正在尝试使用Zlib::GzipReader从管道读取数据来实现流式 Gzip 解压缩器,但我似乎无法弄清楚如何以非阻塞方式进行操作。这是相关的代码:

# In thread A
read, write = IO.pipe

reader = Zlib::GzipReader.new(read) # this blocks

reader.each_line do |line|
  puts "Yay line! #{line}"
end

# In thread B
streaming_http_response do |gzip_chunk|
  write.puts(some_chunk)
end

如何在不将整个压缩字符串读入阅读器的情况下流式传输解压缩的内容?

4

1 回答 1

0

事实证明,Zlib::GzipReader.new只有在它可以读取标题之前才会阻塞。再写一些之后,它工作得很好。

于 2014-01-19T04:05:56.873 回答