How to use crc-32 - 10 common examples

To help you get started, we’ve selected a few crc-32 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitfinexcom / bitfinex-api-node / lib / models / order_book.js View on Github external
if (ask) {
        const price = raw ? ask[0] : Number(preparePrice(ask[0]))

        data.push(
          raw
            ? ask[0]
            : /e/.test(price + '')
              ? price.toFixed(Math.abs((price + '').split('e')[1]) + 1) // i.e. 1.7e-7 to fixed
              : price,
          ask[2]
        )
      }
    }

    return CRC.str(data.join(':'))
  }
github itchio / itch / src / main / broth / unzip.ts View on Github external
time: 100,
    });
    let progressFactor = entry.compressedSize / zipfile.fileSize;
    progressStream.on("progress", info => {
      opts.onProgress({
        progress: progressOffset + (info.percentage / 100) * progressFactor,
      });
    });
    progressStream.pipe(dst);
    src.pipe(progressStream);
    await sf.promised(dst);
    progressOffset += progressFactor;
    await sf.chmod(entryPath, 0o755);

    const fileBuffer = await sf.readFile(entryPath, { encoding: null });
    const signedHash = crc32.buf(fileBuffer);
    // this converts an int32 to an uint32 (which is what yauzl reports)
    const hash = new Uint32Array([signedHash])[0];
    if (hash !== entry.crc32) {
      await sf.unlink(entryPath);
      throw new Error(
        `CRC32 mismatch for ${entry.fileName}: expected ${
          entry.crc32
        } got ${hash}`
      );
    }
  };
github co3moz / knightonline-js / src / core / client.js View on Github external
fragCount = 0;
        }

        let onlyBody;
        let opcode = data[4];
        let subopcode = data[5];
        let didSent = false;

        if (opcode == 0x42) { // COMPRESSED_PACKAGE
          const body = unit.queue(data.slice(5, 4 + length));
          let len = body.int();
          let realLen = body.int();
          let crc = body.int();
          let compressedData = body.skip(len);
          let uncompressedData = lzfjs.decompress(new Uint8Array(compressedData));
          let crcUncompressedData = crc32.buf(uncompressedData, ~-1);
          // if (crcUncompressedData != crc || uncompressedData.length != realLen || compressedData.length != len) {
          //   throw new Error('invalid compressed data!');
          // }

          data = [0xAA, 0x55, ...unit.short(realLen), ...Array.from(uncompressedData), 0x55, 0xAA, ...data.slice(6 + length)]
          client.debug('data uncompressed | ' + Array.from(data).map(x => x.toString(16).padStart(2, '0').toUpperCase()).join(' '));
          opcode = data[4];
          subopcode = data[5];
          length = realLen;
        }


        for (let i = 0; i < waitingTasks.length; i++) {
          let task = waitingTasks[i];
          if (task.opcode) {
            if (opcode != task.opcode) continue;
github co3moz / knightonline-js / src / core / server.js View on Github external
socket.sendCompressed = function (response) {
      let crc = crc32.buf(response, ~-1);
      let compressed = lzfjs.compress(response);

      socket.send([
        0x42, // COMPRESSED_PACKAGE
        ...unit.int(compressed.length),
        ...unit.int(response.length),
        ...unit.int(crc),
        ...compressed
      ]);
    }
github GridPlus / gridplus-sdk / src / util.js View on Github external
function checksum(x) {
  // crc32 returns a signed integer - need to cast it to unsigned
  // Note that this uses the default 0xedb88320 polynomial
  return crc32.buf(x) >>> 0; // Need this to be a uint, hence the bit shift
}
github Multivit4min / TS3-NodeJS-Library / tests / Integration.spec.ts View on Github external
it("should test upload and download of a file", async () => {
    let teamspeak: TeamSpeak|null = null
    try {
      teamspeak = await TeamSpeak.connect({
        ...config,
        protocol: QueryProtocol.RAW,
        queryport: parseInt(process.env.TS3_QUERYPORT_RAW!, 10) || 10011,
        nickname: "JEST RAW"
      })
      const data = fs.readFileSync(`${__dirname}/mocks/filetransfer.png`)
      const crc = crc32.buf(data)
      await teamspeak.uploadFile(`/icon_${crc >>> 0}`, data, 0)
      const download = await teamspeak.downloadIcon(`icon_${crc >>> 0}`)
      expect(crc).toEqual(crc32.buf(download))
      teamspeak.forceQuit()
    } catch (e) {
      if (teamspeak instanceof TeamSpeak) teamspeak.forceQuit()
      throw e
    }
    await wait(2000)
  })
github Multivit4min / TS3-NodeJS-Library / test / integration.js View on Github external
it("should test upload and download of a file", async () => {
    if (!(ts3 instanceof TeamSpeak3))
      throw new Error("can not run test, due to no valid connection")

    const data = fs.readFileSync(`${__dirname}/mocks/filetransfer.png`)
    const crc = crc32.buf(data)
    await ts3.uploadFile(`/icon_${crc >>> 0}`, data, 0)
    const download = await ts3.downloadIcon(`icon_${crc >>> 0}`)
    assert.equal(crc, crc32.buf(download))

  }).timeout(5000)
github SheetJS / js-cfb / types / roundtrip.ts View on Github external
].forEach(path => {
	if(!CFB.find(cfb1, path)) return;
	const d1 = CFB.find(cfb1, path).content, c1 = buf(d1);
	const d2 = CFB.find(cfb2, path).content, c2 = buf(d2);
	if(c1 === c2) return;
	console.log(path); console.log(d1); console.log(d2);
	throw sprintf("%s mismatch: %08X != %08X", path, c1, c2);
});
github sourcegraph / sourcegraph / lsif / src / shared / store / locks.ts View on Github external
function createLockId(name: string): number {
    return crc32.str(name) * ADVISORY_LOCK_ID_SALT
}
github telegram-ru / jobs-bot / deduplicator / minhash.js View on Github external
function shingleHashList(str, kshingles=2) {
  const list = [];
  for (const word of shingles(str, kshingles)) {
    list.push(crc32.str(word) & 0xffffffff);
  }
  return list;
}

crc-32

Pure-JS CRC-32

Apache-2.0
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular crc-32 functions