Class: HTTPX::Plugins::Compression::GZIP::Deflater

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/compression/gzip.rb

Instance Method Summary collapse

Constructor Details

#initializeDeflater



20
21
22
# File 'lib/httpx/plugins/compression/gzip.rb', line 20

def initialize
  @compressed_chunk = "".b
end

Instance Method Details

#deflate(raw, buffer = "".b, chunk_size: 16_384) {|compressed| ... } ⇒ Object

Yields:

  • (compressed)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/httpx/plugins/compression/gzip.rb', line 24

def deflate(raw, buffer = "".b, chunk_size: 16_384)
  gzip = Zlib::GzipWriter.new(self)

  begin
    while (chunk = raw.read(chunk_size))
      gzip.write(chunk)
      gzip.flush
      compressed = compressed_chunk
      buffer << compressed
      yield compressed if block_given?
    end
  ensure
    gzip.close
  end

  return unless (compressed = compressed_chunk)

  buffer << compressed
  yield compressed if block_given?
  buffer
end