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.

21 lines
448 B

7 years ago
  1. // Generated by CoffeeScript 1.7.1
  2. var Buffer, create;
  3. Buffer = require('buffer').Buffer;
  4. create = require('./create');
  5. module.exports = create('crc1', function(buf, previous) {
  6. var accum, byte, crc, _i, _len;
  7. if (!Buffer.isBuffer(buf)) {
  8. buf = Buffer(buf);
  9. }
  10. crc = ~~previous;
  11. accum = 0;
  12. for (_i = 0, _len = buf.length; _i < _len; _i++) {
  13. byte = buf[_i];
  14. accum += byte;
  15. }
  16. crc += accum % 256;
  17. return crc % 256;
  18. });