File tree Expand file tree Collapse file tree 3 files changed +12
-0
lines changed Expand file tree Collapse file tree 3 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ Returns the checksum digest in unsigned form.
44
44
45
45
Returns the hexadecimal representation of the checksum digest. (ie E81722F0)
46
46
47
+ #### size()
48
+
49
+ Returns the raw size/length of passed-through data.
50
+
47
51
### Instance Options
48
52
49
53
Inherits [ Transform Stream] ( http://nodejs.org/api/stream.html#stream_class_stream_transform ) options.
Original file line number Diff line number Diff line change @@ -14,13 +14,16 @@ function CRC32Stream(options) {
14
14
Transform . call ( this , options ) ;
15
15
this . checksum = new Buffer ( 4 ) ;
16
16
this . checksum . writeInt32BE ( 0 , 0 ) ;
17
+
18
+ this . rawSize = 0 ;
17
19
}
18
20
19
21
inherits ( CRC32Stream , Transform ) ;
20
22
21
23
CRC32Stream . prototype . _transform = function ( chunk , encoding , callback ) {
22
24
if ( chunk ) {
23
25
this . checksum = crc32 ( chunk , this . checksum ) ;
26
+ this . rawSize += chunk . length ;
24
27
}
25
28
26
29
callback ( null , chunk ) ;
@@ -34,4 +37,8 @@ CRC32Stream.prototype.hex = function() {
34
37
return this . digest ( ) . toString ( 16 ) . toUpperCase ( ) ;
35
38
} ;
36
39
40
+ CRC32Stream . prototype . size = function ( ) {
41
+ return this . rawSize ;
42
+ } ;
43
+
37
44
module . exports = CRC32Stream ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ describe('CRC32Stream', function() {
16
16
checksum . on ( 'end' , function ( ) {
17
17
assert . equal ( checksum . digest ( ) , 3893830384 ) ;
18
18
assert . equal ( checksum . hex ( ) , 'E81722F0' ) ;
19
+ assert . equal ( checksum . size ( ) , 16384 ) ;
19
20
done ( ) ;
20
21
} ) ;
21
22
You can’t perform that action at this time.
0 commit comments