Question

I'm attempting to implement a streaming Gzip decompressor using Zlib::GzipReader reading data from a pipe, but I can't seem to figure out how to do it in a non-blocking way. Here's the relevant piece of code:

# 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

How can I stream the decompressed content without reading the whole compressed string into the reader?

Était-ce utile?

La solution

It turns out that Zlib::GzipReader.new only blocks until it can read the header. After writing some more it worked just fine.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top