crc1.js 587 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var _buffer = require('buffer');
  3. var _define_crc = require('./define_crc');
  4. var _define_crc2 = _interopRequireDefault(_define_crc);
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. module.exports = (0, _define_crc2.default)('crc1', function (buf, previous) {
  7. if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _buffer.Buffer)(buf);
  8. var crc = ~ ~previous;
  9. var accum = 0;
  10. for (var index = 0; index < buf.length; index++) {
  11. var byte = buf[index];
  12. accum += byte;
  13. }
  14. crc += accum % 256;
  15. return crc % 256;
  16. });