Sha256: 5615b797b61fc78817dba5cbfd3ec894a1e77dd08e745bcf4142e5dd5e0fd9f4
Contents?: true
Size: 999 Bytes
Versions: 1
Compression:
Stored size: 999 Bytes
Contents
# frozen_string_literal: true module Binstream module Streams class FileReader < Base 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 def self.open(path, **kwargs) return new(File.open(path, "rb"), **kwargs) end def filepath @stream.path rescue => e nil end def stell @startpos + @cur_offset end # OVERRIDING 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 def read(length = nil) resp = peek(length) @cur_offset += resp.bytesize return resp end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
binstream-1.0.0 | lib/binstream/streams/file_reader.rb |