Class: Zipping::StreamMeter

Inherits:
Object
  • Object
show all
Defined in:
lib/zipping.rb

Overview

Output stream wrapper that measures size of stream passing through.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_stream) ⇒ StreamMeter

Returns a new instance of StreamMeter.



76
77
78
79
80
# File 'lib/zipping.rb', line 76

def initialize(output_stream)
  @output_stream = output_stream
  @size = 0
  @crc = Zlib.crc32
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



87
88
89
# File 'lib/zipping.rb', line 87

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



86
87
88
# File 'lib/zipping.rb', line 86

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



81
82
83
84
85
# File 'lib/zipping.rb', line 81

def << (data)
  @size += data.length
  @crc = Zlib.crc32 data, @crc
  @output_stream << data
end