README.md
 1  # buffer-crc32
 2  
 3  [![Build Status](https://secure.travis-ci.org/brianloveswords/buffer-crc32.png?branch=master)](http://travis-ci.org/brianloveswords/buffer-crc32)
 4  
 5  crc32 that works with binary data and fancy character sets, outputs
 6  buffer, signed or unsigned data and has tests.
 7  
 8  Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix
 9  
10  # install
11  ```
12  npm install buffer-crc32
13  ```
14  
15  # example
16  ```js
17  var crc32 = require('buffer-crc32');
18  // works with buffers
19  var buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00])
20  crc32(buf) // -> <Buffer 94 5a ab 4a>
21  
22  // has convenience methods for getting signed or unsigned ints
23  crc32.signed(buf) // -> -1805997238
24  crc32.unsigned(buf) // -> 2488970058
25  
26  // will cast to buffer if given a string, so you can
27  // directly use foreign characters safely
28  crc32('自動販売機') // -> <Buffer cb 03 1a c5>
29  
30  // and works in append mode too
31  var partialCrc = crc32('hey');
32  var partialCrc = crc32(' ', partialCrc);
33  var partialCrc = crc32('sup', partialCrc);
34  var partialCrc = crc32(' ', partialCrc);
35  var finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>
36  ```
37  
38  # tests
39  This was tested against the output of zlib's crc32 method. You can run
40  the tests with`npm test` (requires tap)
41  
42  # see also
43  https://github.com/alexgorbatchev/node-crc, `crc.buffer.crc32` also
44  supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).
45  
46  # license
47  MIT/X11