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 130
def num_bytes_remaining
  raise IOError, "stream is unseekable"
end
offset_raw() click to toggle source
# File lib/bindata/io.rb, line 125
def offset_raw
  @offset
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 136
def with_readahead
  mark = @offset
  @read_data = ""
  @in_readahead = true

  class << self
    alias_method :read_raw_without_readahead, :read_raw
    alias_method :read_raw, :read_raw_with_readahead
  end

  begin
    yield
  ensure
    @offset = mark
    @in_readahead = false
  end
end