class BoundedIO

code is obtained from github.com/jordansissel/ruby-arr-pm/blob/8071591173ebb90dea27d5acfdde69a37dcb2744/cpio.rb rubocop:disable all

Attributes

length[R]
remaining[R]

Public Class Methods

new(io, length, &eof_callback) click to toggle source
# File lib/excavate/extractors/cpio/cpio.rb, line 7
def initialize(io, length, &eof_callback)
  @io = io
  @length = length
  @remaining = length

  @eof_callback = eof_callback
  @eof = false
end

Public Instance Methods

eof?() click to toggle source
# File lib/excavate/extractors/cpio/cpio.rb, line 30
def eof?
  return false if @remaining > 0
  return @eof if @eof

  @eof_callback.call
  @eof = true
end
read(size=nil) click to toggle source
# File lib/excavate/extractors/cpio/cpio.rb, line 16
def read(size=nil)
  return nil if eof?
  size = @remaining if size.nil?
  data = @io.read(size)
  @remaining -= data.bytesize
  eof?
  data
end
sysread(size) click to toggle source
# File lib/excavate/extractors/cpio/cpio.rb, line 25
def sysread(size)
  raise EOFError, "end of file reached" if eof?
  read(size)
end