crc1.js 444 B

1234567891011121314151617181920
  1. import { Buffer } from 'buffer';
  2. import createBuffer from './create_buffer';
  3. import defineCrc from './define_crc';
  4. const crc1 = defineCrc('crc1', function(buf, previous) {
  5. if (!Buffer.isBuffer(buf)) buf = createBuffer(buf);
  6. let crc = ~~previous;
  7. let accum = 0;
  8. for (let index = 0; index < buf.length; index++) {
  9. const byte = buf[index];
  10. accum += byte;
  11. }
  12. crc += accum % 256;
  13. return crc % 256;
  14. });
  15. export default crc1;