class HTTPX::Plugins::Compression::GZIP::Encoder

  1. lib/httpx/plugins/compression/gzip.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. deflate

Public Class methods

new ()
[show source]
   # File lib/httpx/plugins/compression/gzip.rb
18 def initialize
19   @compressed_chunk = "".b
20 end

Public Instance methods

deflate (raw, buffer, chunk_size:)
[show source]
   # File lib/httpx/plugins/compression/gzip.rb
22 def deflate(raw, buffer, chunk_size:)
23   gzip = Zlib::GzipWriter.new(self)
24 
25   begin
26     while (chunk = raw.read(chunk_size))
27       gzip.write(chunk)
28       gzip.flush
29       compressed = compressed_chunk
30       buffer << compressed
31       yield compressed if block_given?
32     end
33   ensure
34     gzip.close
35   end
36 
37   return unless (compressed = compressed_chunk)
38 
39   buffer << compressed
40   yield compressed if block_given?
41 end