1 | # CRC32 Stream
|
2 |
|
3 | crc32-stream is a streaming CRC32 checksumer. It uses the [crc](https://www.npmjs.org/package/crc) module behind the scenes to reliably handle binary data and fancy character sets. Data is passed through untouched.
|
4 |
|
5 | ### Install
|
6 |
|
7 | ```bash
|
8 | npm install crc32-stream --save
|
9 | ```
|
10 |
|
11 | You can also use `npm install https://github.com/archiverjs/node-crc32-stream/archive/master.tar.gz` to test upcoming versions.
|
12 |
|
13 | ### Usage
|
14 |
|
15 | #### CRC32Stream
|
16 |
|
17 | Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) options and methods.
|
18 |
|
19 | ```js
|
20 | const {CRC32Stream} = require('crc32-stream');
|
21 |
|
22 | const source = fs.createReadStream('file.txt');
|
23 | const checksum = new CRC32Stream();
|
24 |
|
25 | checksum.on('end', function(err) {
|
26 | // do something with checksum.digest() here
|
27 | });
|
28 |
|
29 | // either pipe it
|
30 | source.pipe(checksum);
|
31 |
|
32 | // or write it
|
33 | checksum.write('string');
|
34 | checksum.end();
|
35 | ```
|
36 |
|
37 | #### DeflateCRC32Stream
|
38 |
|
39 | Inherits [zlib.DeflateRaw](http://nodejs.org/api/zlib.html#zlib_class_zlib_deflateraw) options and methods.
|
40 |
|
41 | ```js
|
42 | const {DeflateCRC32Stream} = require('crc32-stream');
|
43 |
|
44 | const source = fs.createReadStream('file.txt');
|
45 | const checksum = new DeflateCRC32Stream();
|
46 |
|
47 | checksum.on('end', function(err) {
|
48 | // do something with checksum.digest() here
|
49 | });
|
50 |
|
51 | // either pipe it
|
52 | source.pipe(checksum);
|
53 |
|
54 | // or write it
|
55 | checksum.write('string');
|
56 | checksum.end();
|
57 | ```
|
58 |
|
59 | ### Instance API
|
60 |
|
61 | #### digest()
|
62 |
|
63 | Returns the checksum digest in unsigned form.
|
64 |
|
65 | #### hex()
|
66 |
|
67 | Returns the hexadecimal representation of the checksum digest. (ie E81722F0)
|
68 |
|
69 | #### size(compressed)
|
70 |
|
71 | Returns the raw size/length of passed-through data.
|
72 |
|
73 | If `compressed` is `true`, it returns compressed length instead. (DeflateCRC32Stream)
|
74 |
|
75 | ## Things of Interest
|
76 |
|
77 | - [Changelog](https://github.com/archiverjs/node-crc32-stream/releases)
|
78 | - [Contributing](https://github.com/archiverjs/node-crc32-stream/blob/master/CONTRIBUTING.md)
|
79 | - [MIT License](https://github.com/archiverjs/node-crc32-stream/blob/master/LICENSE-MIT)
|