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
Class Method Summary collapse
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.
51 52 53 54 55 56 57 58 |
# File 'lib/protocol/http/body/deflate.rb', line 51 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.
71 72 73 |
# File 'lib/protocol/http/body/deflate.rb', line 71 def input_length @input_length end |
#output_length ⇒ Object (readonly)
Returns the value of attribute output_length.
72 73 74 |
# File 'lib/protocol/http/body/deflate.rb', line 72 def output_length @output_length end |
Class Method Details
.encoding_name(window_size) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/protocol/http/body/deflate.rb', line 41 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
#close(error = nil) ⇒ Object
60 61 62 63 64 |
# File 'lib/protocol/http/body/deflate.rb', line 60 def close(error = nil) @stream.close unless @stream.closed? super end |
#inspect ⇒ Object
82 83 84 |
# File 'lib/protocol/http/body/deflate.rb', line 82 def inspect "#{super} | \#<#{self.class} #{(ratio*100).round(2)}%>" end |
#length ⇒ Object
66 67 68 69 |
# File 'lib/protocol/http/body/deflate.rb', line 66 def length # We don't know the length of the output until after it's been compressed. nil end |
#ratio ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/protocol/http/body/deflate.rb', line 74 def ratio if @input_length != 0 @output_length.to_f / @input_length.to_f else 1.0 end end |