Class: Omnizip::Formats::XzImpl::BlockDecoder::CountingInputStream
- Inherits:
-
Object
- Object
- Omnizip::Formats::XzImpl::BlockDecoder::CountingInputStream
- Defined in:
- lib/omnizip/formats/xz_impl/block_decoder.rb
Overview
Wrapper for counting bytes read from a stream
Instance Attribute Summary collapse
-
#bytes_read ⇒ Object
readonly
Returns the value of attribute bytes_read.
Instance Method Summary collapse
- #eos? ⇒ Boolean
- #getbyte ⇒ Object
-
#initialize(stream) ⇒ CountingInputStream
constructor
A new instance of CountingInputStream.
- #read(length = nil, outbuf = nil) ⇒ Object
- #set_encoding(enc) ⇒ Object
Constructor Details
#initialize(stream) ⇒ CountingInputStream
Returns a new instance of CountingInputStream.
55 56 57 58 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 55 def initialize(stream) @stream = stream @bytes_read = 0 end |
Instance Attribute Details
#bytes_read ⇒ Object (readonly)
Returns the value of attribute bytes_read.
53 54 55 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 53 def bytes_read @bytes_read end |
Instance Method Details
#eos? ⇒ Boolean
75 76 77 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 75 def eos? @stream.eos? end |
#getbyte ⇒ Object
69 70 71 72 73 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 69 def getbyte byte = @stream.getbyte @bytes_read += 1 if byte byte end |
#read(length = nil, outbuf = nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 60 def read(length = nil, outbuf = nil) result = @stream.read(length, outbuf) if result bytes_read = result.bytesize @bytes_read += bytes_read end result end |
#set_encoding(enc) ⇒ Object
79 80 81 |
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 79 def set_encoding(enc) @stream.set_encoding(enc) if @stream.respond_to?(:set_encoding) end |