Class: Ronin::Support::Binary::Stream
- Inherits:
-
Object
- Object
- Ronin::Support::Binary::Stream
- Includes:
- CTypes::Mixin, Methods
- Defined in:
- lib/ronin/support/binary/stream.rb,
lib/ronin/support/binary/stream/methods.rb
Overview
Represents a binary stream of data.
Examples
Creates a binary stream around a file:
stream = Stream.open('path/to/file.bin')
stream.read_uint32
# => 1234
Creates a binary stream around a socket:
socket = TCPSocket.new('example.com',1337)
stream = Stream.new(socket)
stream.read_uint32
# => 1234
stream.write_uint32(0xffffffff)
Defined Under Namespace
Modules: Methods
Instance Attribute Summary collapse
-
#io ⇒ IO, StringIO
readonly
The underlying IO stream.
Attributes included from CTypes::Mixin
#arch, #endian, #os, #type_resolver, #type_system
IO Compatibility Methods collapse
-
#eof? ⇒ Boolean
Determines if EOF has been reached.
-
#external_encoding ⇒ Encoding
Returns the external encoding for the stream.
-
#read(length = nil) ⇒ String
Reads a string from the IO stream.
-
#write(data) ⇒ Integer
Writes String to the IO stream.
Class Method Summary collapse
-
.open(path, mode = 'r') ⇒ Stream
Opens a file in binary mode and returns a stream.
Instance Method Summary collapse
-
#initialize(io, **kwargs) ⇒ Stream
constructor
Initializes the stream.
Methods included from Methods
#read_array, #read_array_of, #read_array_of_byte, #read_array_of_char, #read_array_of_double, #read_array_of_float, #read_array_of_float32, #read_array_of_float64, #read_array_of_int, #read_array_of_int16, #read_array_of_int32, #read_array_of_int64, #read_array_of_int8, #read_array_of_long, #read_array_of_long_long, #read_array_of_short, #read_array_of_uchar, #read_array_of_uint, #read_array_of_uint16, #read_array_of_uint32, #read_array_of_uint64, #read_array_of_uint8, #read_array_of_ulong, #read_array_of_ulong_long, #read_array_of_ushort, #read_buffer, #read_byte, #read_char, #read_double, #read_float, #read_float32, #read_float64, #read_int, #read_int16, #read_int32, #read_int64, #read_int8, #read_into, #read_long, #read_long_long, #read_short, #read_string, #read_struct, #read_uchar, #read_uint, #read_uint16, #read_uint32, #read_uint64, #read_uint8, #read_ulong, #read_ulong_long, #read_union, #read_ushort, #read_value, #write_array_of, #write_array_of_byte, #write_array_of_char, #write_array_of_double, #write_array_of_float, #write_array_of_float32, #write_array_of_float64, #write_array_of_int, #write_array_of_int16, #write_array_of_int32, #write_array_of_int64, #write_array_of_int8, #write_array_of_long, #write_array_of_long_long, #write_array_of_short, #write_array_of_uchar, #write_array_of_uint, #write_array_of_uint16, #write_array_of_uint32, #write_array_of_uint64, #write_array_of_uint8, #write_array_of_ulong, #write_array_of_ulong_long, #write_array_of_ushort, #write_byte, #write_char, #write_double, #write_float, #write_float32, #write_float64, #write_int, #write_int16, #write_int32, #write_int64, #write_int8, #write_long, #write_long_long, #write_short, #write_string, #write_uchar, #write_uint, #write_uint16, #write_uint32, #write_uint64, #write_uint8, #write_ulong, #write_ulong_long, #write_ushort, #write_value
Methods included from CTypes::Mixin
Constructor Details
#initialize(io, **kwargs) ⇒ Stream
Initializes the stream.
The desired architecture for the values of the IO stream.
78 79 80 81 82 |
# File 'lib/ronin/support/binary/stream.rb', line 78 def initialize(io, **kwargs) initialize_type_system(**kwargs) @io = io end |
Instance Attribute Details
#io ⇒ IO, StringIO (readonly)
The underlying IO stream.
56 57 58 |
# File 'lib/ronin/support/binary/stream.rb', line 56 def io @io end |
Class Method Details
Instance Method Details
#eof? ⇒ Boolean
Determines if EOF has been reached.
118 119 120 |
# File 'lib/ronin/support/binary/stream.rb', line 118 def eof? @io.eof? end |
#external_encoding ⇒ Encoding
Returns the external encoding for the stream.
109 110 111 |
# File 'lib/ronin/support/binary/stream.rb', line 109 def external_encoding @io.external_encoding end |
#read(length = nil) ⇒ String
Reads a string from the IO stream.
131 132 133 |
# File 'lib/ronin/support/binary/stream.rb', line 131 def read(length=nil) @io.read(length) end |
#write(data) ⇒ Integer
Writes String to the IO stream.
144 145 146 |
# File 'lib/ronin/support/binary/stream.rb', line 144 def write(data) @io.write(data) end |