Class: Protocol::HTTP::Body::ZStream
- Defined in:
- lib/protocol/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_length ⇒ Object
readonly
Returns the value of attribute input_length.
-
#output_length ⇒ Object
readonly
Returns the value of attribute output_length.
Attributes inherited from Wrapper
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
-
#initialize(body, stream) ⇒ ZStream
constructor
A new instance of ZStream.
- #inspect ⇒ Object
- #length ⇒ Object
- #ratio ⇒ Object
Methods inherited from Wrapper
#call, #empty?, #finish, #read, #ready?, #stream?, wrap
Methods inherited from Readable
#call, #each, #empty?, #finish, #join, #read, #ready?, #stream?
Constructor Details
#initialize(body, stream) ⇒ ZStream
Returns a new instance of ZStream.
24 25 26 27 28 29 30 31 |
# File 'lib/protocol/http/body/deflate.rb', line 24 def initialize(body, stream) super(body) @stream = stream @input_length = 0 @output_length = 0 end |
Instance Attribute Details
#input_length ⇒ Object (readonly)
Returns the value of attribute input_length.
44 45 46 |
# File 'lib/protocol/http/body/deflate.rb', line 44 def input_length @input_length end |
#output_length ⇒ Object (readonly)
Returns the value of attribute output_length.
45 46 47 |
# File 'lib/protocol/http/body/deflate.rb', line 45 def output_length @output_length end |
Instance Method Details
#close(error = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/protocol/http/body/deflate.rb', line 33 def close(error = nil) @stream.close unless @stream.closed? super end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/protocol/http/body/deflate.rb', line 55 def inspect "#{super} | \#<#{self.class} #{(ratio*100).round(2)}%>" end |
#length ⇒ Object
39 40 41 42 |
# File 'lib/protocol/http/body/deflate.rb', line 39 def length # We don't know the length of the output until after it's been compressed. nil end |
#ratio ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/protocol/http/body/deflate.rb', line 47 def ratio if @input_length != 0 @output_length.to_f / @input_length.to_f else 1.0 end end |