Class: HTTPX::Transcoder::Deflate::Deflater

Inherits:
HTTPX::Transcoder::Deflater show all
Defined in:
lib/httpx/transcoder/deflate.rb

Instance Attribute Summary

Attributes inherited from HTTPX::Transcoder::Deflater

#content_type

Instance Method Summary collapse

Methods inherited from HTTPX::Transcoder::Deflater

#bytesize, #close, #initialize, #read, #rewind

Constructor Details

This class inherits a constructor from HTTPX::Transcoder::Deflater

Instance Method Details

#deflate(chunk) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/httpx/transcoder/deflate.rb', line 10

def deflate(chunk)
  @deflater ||= Zlib::Deflate.new

  unless chunk.nil?
    chunk = @deflater.deflate(chunk)

    # deflate call may return nil, while still
    # retaining the last chunk in the deflater.
    return chunk unless chunk.empty?
  end

  return if @deflater.closed?

  last = @deflater.finish
  @deflater.close

  last unless last.empty?
end