Class: Binstream::Streams::FileReader
- Defined in:
- lib/binstream/streams/file_reader.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #filepath ⇒ Object
-
#initialize(path_or_io, **kwargs) ⇒ FileReader
constructor
A new instance of FileReader.
-
#peek(length = nil) ⇒ Object
OVERRIDING.
- #read(length = nil) ⇒ Object
- #stell ⇒ Object
Methods inherited from Base
#dump, #eof?, #method_missing, #peek_slice, #read_binary, #read_bool, #read_byte, #read_double, #read_doublebe, #read_float, #read_floatbe, #read_hash, #read_int16, #read_int16be, #read_int32, #read_int32be, #read_int64, #read_int64be, #read_int8, #read_single, #read_string, #read_uint16, #read_uint16be, #read_uint32, #read_uint32be, #read_uint64, #read_uint64be, #read_uint8, #read_unpack, #remaining, #remaining?, #reset, #rewind, #seek, #setup_stopper, #slice, #slice!, #starting_offset, #tell, #total_size, #valid_position?
Methods included from Tracking
included, #track, #track_pos, #without_tracking
Constructor Details
#initialize(path_or_io, **kwargs) ⇒ FileReader
Returns a new instance of FileReader.
6 7 8 9 10 11 12 |
# File 'lib/binstream/streams/file_reader.rb', line 6 def initialize(path_or_io, **kwargs) if path_or_io.is_a?(::IO) super(path_or_io, **kwargs) else super(File.open(path_or_io, "rb"), **kwargs) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Binstream::Streams::Base
Class Method Details
.open(path, **kwargs) ⇒ Object
14 15 16 |
# File 'lib/binstream/streams/file_reader.rb', line 14 def self.open(path, **kwargs) return new(File.open(path, "rb"), **kwargs) end |
Instance Method Details
#filepath ⇒ Object
18 19 20 21 22 |
# File 'lib/binstream/streams/file_reader.rb', line 18 def filepath @stream.path rescue => e nil end |
#peek(length = nil) ⇒ Object
OVERRIDING
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/binstream/streams/file_reader.rb', line 30 def peek(length = nil) read_size = (length || size) if remaining - read_size < 0 raise StreamOverrunError.new(read_size, remaining, @startpos + @cur_offset) end resp = @stream.pread(read_size, @startpos + @cur_offset) return resp end |
#read(length = nil) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/binstream/streams/file_reader.rb', line 41 def read(length = nil) resp = peek(length) @cur_offset += resp.bytesize return resp end |
#stell ⇒ Object
24 25 26 |
# File 'lib/binstream/streams/file_reader.rb', line 24 def stell @startpos + @cur_offset end |