Class: Async::HTTP::Body::Inflate

Inherits:
ZStream show all
Defined in:
lib/async/http/body/inflate.rb

Constant Summary

Constants inherited from ZStream

ZStream::DEFAULT_LEVEL, ZStream::DEFLATE, ZStream::ENCODINGS, ZStream::GZIP

Instance Attribute Summary

Attributes inherited from ZStream

#input_length, #output_length

Attributes inherited from Wrapper

#body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ZStream

#close, encoding_name, #initialize, #inspect, #length, #ratio

Methods inherited from Wrapper

#close, #empty?, #finish, #initialize, #length

Methods inherited from Readable

#close, #each, #empty?, #finish, #join, #length

Constructor Details

This class inherits a constructor from Async::HTTP::Body::ZStream

Class Method Details

.for(body, encoding = GZIP) ⇒ Object



29
30
31
# File 'lib/async/http/body/inflate.rb', line 29

def self.for(body, encoding = GZIP)
  self.new(body, Zlib::Inflate.new(encoding))
end

Instance Method Details

#readObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/async/http/body/inflate.rb', line 33

def read
  return if @stream.closed?
  
  if chunk = super
    @input_length += chunk.bytesize
    
    chunk = @stream.inflate(chunk)
    
    @output_length += chunk.bytesize
  else
    chunk = @stream.finish
    
    @output_length += chunk.bytesize
    
    @stream.close
  end
  
  return chunk.empty? ? nil : chunk
end