crc1.js 794 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _buffer = require('buffer');
  6. var _create_buffer = require('./create_buffer');
  7. var _create_buffer2 = _interopRequireDefault(_create_buffer);
  8. var _define_crc = require('./define_crc');
  9. var _define_crc2 = _interopRequireDefault(_define_crc);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. var crc1 = (0, _define_crc2.default)('crc1', function (buf, previous) {
  12. if (!_buffer.Buffer.isBuffer(buf)) buf = (0, _create_buffer2.default)(buf);
  13. var crc = ~~previous;
  14. var accum = 0;
  15. for (var index = 0; index < buf.length; index++) {
  16. var byte = buf[index];
  17. accum += byte;
  18. }
  19. crc += accum % 256;
  20. return crc % 256;
  21. });
  22. exports.default = crc1;