Class: Omnizip::Formats::XzImpl::BlockDecoder::CountingInputStream

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/formats/xz_impl/block_decoder.rb

Overview

Wrapper for counting bytes read from a stream

Instance Attribute Summary collapse

Instance Method Summary collapse

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_readObject (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

Returns:

  • (Boolean)


75
76
77
# File 'lib/omnizip/formats/xz_impl/block_decoder.rb', line 75

def eos?
  @stream.eos?
end

#getbyteObject



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