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.

98 lines
3.7 KiB

8 years ago
  1. # crc
  2. [![GitTip](http://img.shields.io/gittip/alexgorbatchev.svg?style=flat)](https://www.gittip.com/alexgorbatchev/)
  3. [![Dependency status](http://img.shields.io/david/alexgorbatchev/node-crc.svg?style=flat)](https://david-dm.org/alexgorbatchev/node-crc)
  4. [![devDependency Status](http://img.shields.io/david/dev/alexgorbatchev/node-crc.svg?style=flat)](https://david-dm.org/alexgorbatchev/node-crc#info=devDependencies)
  5. [![Build Status](http://img.shields.io/travis/alexgorbatchev/node-crc.svg?style=flat&branch=master)](https://travis-ci.org/alexgorbatchev/node-crc)
  6. [![NPM](https://nodei.co/npm/crc.svg?style=flat)](https://npmjs.org/package/node-crc)
  7. Module for calculating Cyclic Redundancy Check (CRC).
  8. ## Features
  9. * Full test suite comparing values against reference `pycrc` implementation.
  10. * Version 3.x is 3x to 4x faster than version 2.x.
  11. * Pure JavaScript implementation, no dependencies.
  12. * Provides CRC Tables for optimized calculations.
  13. * Provides support for the following CRC algorithms:
  14. * CRC1 `crc.crc1(…)`
  15. * CRC8 `crc.crc8(…)`
  16. * CRC8 1-Wire `crc.crc81wire(…)`
  17. * CRC16 `crc.crc16(…)`
  18. * CRC16 CCITT `crc.crc16ccitt(…)`
  19. * CRC16 Modbus `crc.crc16modbus(…)`
  20. * CRC24 `crc.crc24(…)`
  21. * CRC32 `crc.crc32(…)`
  22. ## IMPORTANT
  23. If you've used `crc` module prior to version 2.x, you might have some inconsistentcies with the current implementation because it relied on very old code and wasn't checked against reference implementation. If you upgrading from 1.x, please take special care.
  24. ## Support
  25. <a href="https://blockchain.info/address/1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ"><img src="bitcoin.png" width="150" align="right"/></a> Please support me on [GitTip](https://www.gittip.com/alexgorbatchev/). I've spend days developing and grooming this module and hope to spend more time. If you have bitcoin, please use the QR code or this wallet address [`1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ`](https://blockchain.info/address/1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ):
  26. ## Installation
  27. npm install crc
  28. ## Running tests
  29. $ npm install
  30. $ npm test
  31. ## Usage Example
  32. Calculate a CRC32:
  33. var crc = require('crc');
  34. crc.crc32('hello').toString(16);
  35. # => "3610a686"
  36. Calculate a CRC32 of a file:
  37. crc.crc32(fs.readFileSync('README.md', 'utf8')).toString(16);
  38. # => "127ad531"
  39. Or using a `Buffer`:
  40. crc.crc32(fs.readFileSync('README.md')).toString(16);
  41. # => "127ad531"
  42. Incrementally calculate a CRC32:
  43. value = crc32('one');
  44. value = crc32('two', value);
  45. value = crc32('three', value);
  46. value.toString(16);
  47. # => "09e1c092"
  48. ## Thanks!
  49. [pycrc](http://www.tty1.net/pycrc/) library is which the source of all of the CRC tables.
  50. # License
  51. The MIT License (MIT)
  52. Copyright (c) 2014 Alex Gorbatchev
  53. Permission is hereby granted, free of charge, to any person obtaining a copy
  54. of this software and associated documentation files (the "Software"), to deal
  55. in the Software without restriction, including without limitation the rights
  56. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  57. copies of the Software, and to permit persons to whom the Software is
  58. furnished to do so, subject to the following conditions:
  59. The above copyright notice and this permission notice shall be included in
  60. all copies or substantial portions of the Software.
  61. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  62. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  63. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  64. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  65. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  66. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  67. THE SOFTWARE.