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