Class: Async::HTTP::Body::ZStream
- Defined in:
- lib/async/http/body/deflate.rb
Constant Summary collapse
- DEFAULT_LEVEL =
7
- DEFLATE =
-Zlib::MAX_WBITS
- GZIP =
Zlib::MAX_WBITS | 16
- ENCODINGS =
{ 'deflate' => DEFLATE, 'gzip' => GZIP, }
Instance Attribute Summary collapse
-
#input_size ⇒ Object
readonly
Returns the value of attribute input_size.
-
#output_size ⇒ Object
readonly
Returns the value of attribute output_size.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body, stream) ⇒ ZStream
constructor
A new instance of ZStream.
- #inspect ⇒ Object
- #ratio ⇒ Object
- #stop(error) ⇒ Object
Methods inherited from Wrapper
Methods inherited from Readable
#close, #each, #empty?, #join, #length, #read
Constructor Details
#initialize(body, stream) ⇒ ZStream
Returns a new instance of ZStream.
49 50 51 52 53 54 55 56 |
# File 'lib/async/http/body/deflate.rb', line 49 def initialize(body, stream) super(body) @stream = stream @input_size = 0 @output_size = 0 end |
Instance Attribute Details
#input_size ⇒ Object (readonly)
Returns the value of attribute input_size.
58 59 60 |
# File 'lib/async/http/body/deflate.rb', line 58 def input_size @input_size end |
#output_size ⇒ Object (readonly)
Returns the value of attribute output_size.
59 60 61 |
# File 'lib/async/http/body/deflate.rb', line 59 def output_size @output_size end |
Class Method Details
.encoding_name(window_size) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/async/http/body/deflate.rb', line 39 def self.encoding_name(window_size) if window_size <= -8 return 'deflate' elsif window_size >= 16 return 'gzip' else return 'compress' end end |
Instance Method Details
#inspect ⇒ Object
72 73 74 |
# File 'lib/async/http/body/deflate.rb', line 72 def inspect "#{super} | \#<#{self.class} #{(ratio*100).round(2)}%>" end |
#ratio ⇒ Object
61 62 63 |
# File 'lib/async/http/body/deflate.rb', line 61 def ratio @output_size.to_f / @input_size.to_f end |
#stop(error) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/async/http/body/deflate.rb', line 65 def stop(error) # There are two ways for the stream to be closed. Either #read returns nil or #stop is called. @stream.close unless @stream.closed? super end |