Class: BoundedIO
- Inherits:
-
Object
- Object
- BoundedIO
- Defined in:
- lib/excavate/extractors/cpio/cpio.rb
Overview
code is obtained from github.com/jordansissel/ruby-arr-pm/blob/8071591173ebb90dea27d5acfdde69a37dcb2744/cpio.rb rubocop:disable all
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#remaining ⇒ Object
readonly
Returns the value of attribute remaining.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(io, length, &eof_callback) ⇒ BoundedIO
constructor
A new instance of BoundedIO.
- #read(size = nil) ⇒ Object
- #sysread(size) ⇒ Object
Constructor Details
#initialize(io, length, &eof_callback) ⇒ BoundedIO
Returns a new instance of BoundedIO.
7 8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
4 5 6 |
# File 'lib/excavate/extractors/cpio/cpio.rb', line 4 def length @length end |
#remaining ⇒ Object (readonly)
Returns the value of attribute remaining.
5 6 7 |
# File 'lib/excavate/extractors/cpio/cpio.rb', line 5 def remaining @remaining end |
Instance Method Details
#eof? ⇒ Boolean
30 31 32 33 34 35 36 |
# 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) ⇒ Object
16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 28 |
# File 'lib/excavate/extractors/cpio/cpio.rb', line 25 def sysread(size) raise EOFError, "end of file reached" if eof? read(size) end |