UNPKG

1.98 kBMarkdownView Raw
1# CRC32 Stream
2
3crc32-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
8npm install crc32-stream --save
9```
10
11You 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
17Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) options and methods.
18
19```js
20const {CRC32Stream} = require('crc32-stream');
21
22const source = fs.createReadStream('file.txt');
23const checksum = new CRC32Stream();
24
25checksum.on('end', function(err) {
26 // do something with checksum.digest() here
27});
28
29// either pipe it
30source.pipe(checksum);
31
32// or write it
33checksum.write('string');
34checksum.end();
35```
36
37#### DeflateCRC32Stream
38
39Inherits [zlib.DeflateRaw](http://nodejs.org/api/zlib.html#zlib_class_zlib_deflateraw) options and methods.
40
41```js
42const {DeflateCRC32Stream} = require('crc32-stream');
43
44const source = fs.createReadStream('file.txt');
45const checksum = new DeflateCRC32Stream();
46
47checksum.on('end', function(err) {
48 // do something with checksum.digest() here
49});
50
51// either pipe it
52source.pipe(checksum);
53
54// or write it
55checksum.write('string');
56checksum.end();
57```
58
59### Instance API
60
61#### digest()
62
63Returns the checksum digest in unsigned form.
64
65#### hex()
66
67Returns the hexadecimal representation of the checksum digest. (ie E81722F0)
68
69#### size(compressed)
70
71Returns the raw size/length of passed-through data.
72
73If `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)