Class: Async::HTTP::Body::Deflate

Inherits:
ZStream show all
Defined in:
lib/async/http/body/deflate.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, #inspect, #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, window_size = GZIP, level = DEFAULT_LEVEL) ⇒ Object



86
87
88
# File 'lib/async/http/body/deflate.rb', line 86

def self.for(body, window_size = GZIP, level = DEFAULT_LEVEL)
  self.new(body, Zlib::Deflate.new(level, window_size))
end

Instance Method Details

#readObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/async/http/body/deflate.rb', line 90

def read
  return if @stream.finished?
  
  # The stream might have been closed while waiting for the chunk to come in.
  if chunk = super
    @input_length += chunk.bytesize
    
    chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
    
    @output_length += chunk.bytesize
    
    return chunk
  elsif !@stream.closed?
    chunk = @stream.finish
    
    @output_length += chunk.bytesize
    
    return chunk.empty? ? nil : chunk
  end
end