我正在尝试使用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
如何在不将整个压缩字符串读入阅读器的情况下流式传输解压缩的内容?