You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

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