Class: Krakow::ConnectionFeatures::Deflate::Io
- Inherits:
-
Object
- Object
- Krakow::ConnectionFeatures::Deflate::Io
- Defined in:
- lib/krakow/connection_features/deflate.rb
Overview
Deflatable IO
Instance Attribute Summary (collapse)
-
- (Object) buffer
readonly
Returns the value of attribute buffer.
-
- (Object) deflator
readonly
Returns the value of attribute deflator.
-
- (Object) headers
readonly
Returns the value of attribute headers.
-
- (Object) inflator
readonly
Returns the value of attribute inflator.
-
- (Object) io
readonly
Returns the value of attribute io.
Instance Method Summary (collapse)
-
- (TrueClass) close(*args)
Close the IO.
-
- (Io) initialize(io, args = {})
constructor
Create new deflatable IO.
-
- (Object) method_missing(*args)
Proxy to underlying socket.
-
- (String) read_stream
Read contents from stream.
-
- (String) recv(n)
(also: #read)
Receive bytes from the IO.
-
- (Integer) write(string)
Write string to IO.
Constructor Details
- (Io) initialize(io, args = {})
Create new deflatable IO
17 18 19 20 21 22 |
# File 'lib/krakow/connection_features/deflate.rb', line 17 def initialize(io, args={}) @io = io @buffer = '' @inflator = Zlib::Inflate.new(-Zlib::MAX_WBITS) @deflator = Zlib::Deflate.new(nil, -Zlib::MAX_WBITS) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(*args)
Proxy to underlying socket
28 29 30 |
# File 'lib/krakow/connection_features/deflate.rb', line 28 def method_missing(*args) io.__send__(*args) end |
Instance Attribute Details
- (Object) buffer (readonly)
Returns the value of attribute buffer
11 12 13 |
# File 'lib/krakow/connection_features/deflate.rb', line 11 def buffer @buffer end |
- (Object) deflator (readonly)
Returns the value of attribute deflator
11 12 13 |
# File 'lib/krakow/connection_features/deflate.rb', line 11 def deflator @deflator end |
- (Object) headers (readonly)
Returns the value of attribute headers
11 12 13 |
# File 'lib/krakow/connection_features/deflate.rb', line 11 def headers @headers end |
- (Object) inflator (readonly)
Returns the value of attribute inflator
11 12 13 |
# File 'lib/krakow/connection_features/deflate.rb', line 11 def inflator @inflator end |
- (Object) io (readonly)
Returns the value of attribute io
11 12 13 |
# File 'lib/krakow/connection_features/deflate.rb', line 11 def io @io end |
Instance Method Details
- (TrueClass) close(*args)
Close the IO
72 73 74 75 76 77 |
# File 'lib/krakow/connection_features/deflate.rb', line 72 def close(*args) super deflator.deflate(nil, Zlib::FINISH) deflator.close true end |
- (String) read_stream
Read contents from stream
48 49 50 51 52 53 |
# File 'lib/krakow/connection_features/deflate.rb', line 48 def read_stream str = io.read unless(str.empty?) buffer << inflator.inflate(str) end end |
- (String) recv(n) Also known as: read
Receive bytes from the IO
36 37 38 39 40 41 42 |
# File 'lib/krakow/connection_features/deflate.rb', line 36 def recv(n) until(buffer.length >= n) read_stream sleep(0.1) unless buffer.length >= n end buffer.slice!(0, n) end |
- (Integer) write(string)
Write string to IO
59 60 61 62 63 64 65 66 67 |
# File 'lib/krakow/connection_features/deflate.rb', line 59 def write(string) unless(string.empty?) output = deflator.deflate(string) output << deflator.flush io.write(output) else 0 end end |