No Description
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.

crc.js 1021B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.crc32cToString = exports.crc32c = void 0;
  4. function makeCRCTable(poly) {
  5. let c;
  6. const crcTable = [];
  7. for (let n = 0; n < 256; n++) {
  8. c = n;
  9. for (let k = 0; k < 8; k++) {
  10. c = c & 1 ? poly ^ (c >>> 1) : c >>> 1;
  11. }
  12. crcTable[n] = c;
  13. }
  14. return crcTable;
  15. }
  16. const CRC32C_TABLE = makeCRCTable(0x82f63b78);
  17. function crc32c(bytes) {
  18. let crc = 0 ^ -1;
  19. for (let i = 0; i < bytes.length; i++) {
  20. const byte = bytes[i];
  21. const nLookupIndex = (crc ^ byte) & 0xff;
  22. crc = (crc >>> 8) ^ CRC32C_TABLE[nLookupIndex];
  23. }
  24. return (crc ^ -1) >>> 0;
  25. }
  26. exports.crc32c = crc32c;
  27. function crc32cToString(crc32cValue) {
  28. const value = typeof crc32cValue === "string" ? Number.parseInt(crc32cValue) : crc32cValue;
  29. const buffer = Buffer.alloc(4);
  30. buffer.writeUint32BE(value);
  31. return buffer.toString("base64");
  32. }
  33. exports.crc32cToString = crc32cToString;