module BinData::IO::Common::SeekableStream
Use seek and pos on seekable streams
Public Instance Methods
num_bytes_remaining()
click to toggle source
The number of bytes remaining in the input stream.
# File lib/bindata/io.rb, line 71 def num_bytes_remaining start_mark = @raw_io.pos @raw_io.seek(0, ::IO::SEEK_END) end_mark = @raw_io.pos if @buffer_end_points if @buffer_end_points[1] < end_mark end_mark = @buffer_end_points[1] end end bytes_remaining = end_mark - start_mark @raw_io.seek(start_mark, ::IO::SEEK_SET) bytes_remaining end
with_readahead() { || ... }
click to toggle source
All io calls in block
are rolled back after this method
completes.
# File lib/bindata/io.rb, line 90 def with_readahead mark = @raw_io.pos begin yield ensure @raw_io.seek(mark, ::IO::SEEK_SET) end end
Private Instance Methods
offset_raw()
click to toggle source
# File lib/bindata/io.rb, line 106 def offset_raw @raw_io.pos - @initial_pos end
read_raw(n)
click to toggle source
# File lib/bindata/io.rb, line 114 def read_raw(n) @raw_io.read(n) end
seek_raw(n)
click to toggle source
# File lib/bindata/io.rb, line 110 def seek_raw(n) @raw_io.seek(n, ::IO::SEEK_CUR) end
stream_init()
click to toggle source
# File lib/bindata/io.rb, line 102 def stream_init @initial_pos = @raw_io.pos end
write_raw(data)
click to toggle source
# File lib/bindata/io.rb, line 118 def write_raw(data) @raw_io.write(data) end