Class: WebSocket::Driver::Hybi::StreamReader
- Inherits:
-
Object
- Object
- WebSocket::Driver::Hybi::StreamReader
- Defined in:
- lib/websocket/driver/hybi/stream_reader.rb
Instance Method Summary collapse
-
#initialize ⇒ StreamReader
constructor
A new instance of StreamReader.
- #put(string) ⇒ Object
- #read(length) ⇒ Object
Constructor Details
#initialize ⇒ StreamReader
Returns a new instance of StreamReader.
6 7 8 |
# File 'lib/websocket/driver/hybi/stream_reader.rb', line 6 def initialize @buffer = Driver.encode('', :binary) end |
Instance Method Details
#put(string) ⇒ Object
10 11 12 13 |
# File 'lib/websocket/driver/hybi/stream_reader.rb', line 10 def put(string) return unless string and string.bytesize > 0 @buffer << Driver.encode(string, :binary) end |
#read(length) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/websocket/driver/hybi/stream_reader.rb', line 15 def read(length) buffer_size = @buffer.bytesize return nil if length > buffer_size chunk = @buffer.byteslice(0, length) @buffer = @buffer.byteslice(length, buffer_size - length) chunk end |