Module: HTTPX::Plugins::Compression::Deflate::Encoder

Defined in:
lib/httpx/plugins/compression/deflate.rb

Class Method Summary collapse

Class Method Details

.deflate(raw, buffer, chunk_size:) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/httpx/plugins/compression/deflate.rb', line 19

def deflate(raw, buffer, chunk_size:)
  deflater = Zlib::Deflate.new(Zlib::BEST_COMPRESSION,
                               Zlib::MAX_WBITS,
                               Zlib::MAX_MEM_LEVEL,
                               Zlib::HUFFMAN_ONLY)
  while (chunk = raw.read(chunk_size))
    compressed = deflater.deflate(chunk)
    buffer << compressed
    yield compressed if block_given?
  end
  last = deflater.finish
  buffer << last
  yield last if block_given?
ensure
  deflater.close
end