module BinData::IO::Common::UnSeekableStream
Manually keep track of offset for unseekable 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 111 def num_bytes_remaining raise IOError, "stream is unseekable" end
offset_raw()
click to toggle source
# File lib/bindata/io.rb, line 106 def offset_raw @offset end
Private Instance Methods
read_raw(n)
click to toggle source
# File lib/bindata/io.rb, line 122 def read_raw(n) data = @raw_io.read(n) @offset += data.size if data data end
seek_raw(n)
click to toggle source
# File lib/bindata/io.rb, line 133 def seek_raw(n) raise IOError, "stream is unseekable" if n < 0 # NOTE: how do we seek on a writable stream? # skip over data in 8k blocks while n > 0 bytes_to_read = [n, 8192].min read_raw(bytes_to_read) n -= bytes_to_read end end
stream_init()
click to toggle source
# File lib/bindata/io.rb, line 118 def stream_init @offset = 0 end
write_raw(data)
click to toggle source
# File lib/bindata/io.rb, line 128 def write_raw(data) @offset += data.size @raw_io.write(data) end