How to use buffer-crc32 - 10 common examples

To help you get started, we’ve selected a few buffer-crc32 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 oleksiyk / kafka / test / 07.compression.js View on Github external
it('should send/receive with async Gzip compression (>32kb)', function () {
            var buf = new Buffer(90 * 1024), crc = crc32.signed(buf);

            dataHandlerSpy.reset();

            return producer.send({
                topic: 'kafka-test-topic',
                partition: 0,
                message: { value: buf }
            }, { codec: Kafka.COMPRESSION_GZIP })
            .delay(300)
            .then(function () {
                dataHandlerSpy.should.have.been.called; // eslint-disable-line
                dataHandlerSpy.lastCall.args[0].should.be.an('array').and.have.length(1);
                dataHandlerSpy.lastCall.args[1].should.be.a('string', 'kafka-test-topic');
                dataHandlerSpy.lastCall.args[2].should.be.a('number', 0);

                dataHandlerSpy.lastCall.args[0][0].should.be.an('object');
github oleksiyk / kafka / test / 08.connection.js View on Github external
.then(function () {
            dataHandlerSpy.should.have.been.called; // eslint-disable-line
            dataHandlerSpy.lastCall.args[0].should.be.an('array').and.have.length(1);
            dataHandlerSpy.lastCall.args[1].should.be.a('string', 'kafka-test-topic');
            dataHandlerSpy.lastCall.args[2].should.be.a('number', 0);

            dataHandlerSpy.lastCall.args[0][0].should.be.an('object');
            dataHandlerSpy.lastCall.args[0][0].should.have.property('message').that.is.an('object');
            dataHandlerSpy.lastCall.args[0][0].message.should.have.property('value');
            crc32.signed(dataHandlerSpy.lastCall.args[0][0].message.value).should.be.eql(crc);
        });
    });
github walletpass / pass-js / src / template.ts View on Github external
const zip = await unzipBuffer(buffer);
    if (zip.entryCount < 1)
      throw new TypeError(`Provided ZIP buffer contains no entries`);

    let template = new Template();

    for await (const entry of zip) {
      if (entry.fileName.endsWith('/')) continue;

      if (/\/?pass\.json$/i.test(entry.fileName)) {
        if (template.style)
          throw new TypeError(
            `Archive contains more than one pass.json - found ${entry.fileName}`,
          );
        const buf = await zip.getBuffer(entry);
        if (crc32(buf) !== entry.crc32)
          throw new Error(
            `CRC32 does not match for ${entry.fileName}, expected ${
              entry.crc32
            }, got ${crc32(buf)}`,
          );
        const passJSON = JSON.parse(stripJsonComments(buf.toString('utf8')));
        template = new Template(
          undefined,
          passJSON,
          template.images,
          template.localization,
        );
      } else {
        // test if it's an image
        const img = template.images.parseFilename(entry.fileName);
        if (img) {
github walletpass / pass-js / src / template.ts View on Github external
entry.crc32
            }, got ${crc32(buf)}`,
          );
        const passJSON = JSON.parse(stripJsonComments(buf.toString('utf8')));
        template = new Template(
          undefined,
          passJSON,
          template.images,
          template.localization,
        );
      } else {
        // test if it's an image
        const img = template.images.parseFilename(entry.fileName);
        if (img) {
          const imgBuffer = await zip.getBuffer(entry);
          if (crc32(imgBuffer) !== entry.crc32)
            throw new Error(
              `CRC32 does not match for ${entry.fileName}, expected ${
                entry.crc32
              }, got ${crc32(imgBuffer)}`,
            );
          await template.images.add(
            img.imageType,
            imgBuffer,
            img.density,
            img.lang,
          );
        } else {
          // the only option lest is 'pass.strings' file in localization folder
          const test = /(^|\/)(?[-_a-z]+)\.lproj\/pass\.strings$/i.exec(
            entry.fileName,
          );
github mhart / dynalite / index.js View on Github external
function sendData(req, res, data, statusCode) {
  var body = JSON.stringify(data)
  req.removeAllListeners()
  res.statusCode = statusCode || 200
  res.setHeader('x-amz-crc32', crc32.unsigned(body))
  res.setHeader('Content-Type', res.contentType)
  res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'))
  // AWS doesn't send a 'Connection' header but seems to use keep-alive behaviour
  // res.setHeader('Connection', '')
  // res.shouldKeepAlive = false
  res.end(body)
}
github Wizcorp / Jeff / lib / CanvasRenderer / SwfImgRenderer / PngWriter.js View on Github external
PngWriter.prototype._addChunk = function (name, data, len) {
	var buf = new Buffer(len + 12, 'binary'); // 4 bytes for name + 4 bytes for palette length + 4 bytes for crc
	buf.writeUInt32BE(len, 0);
	buf.write(name, 4, 4);
	if (typeof data === 'string') {
		buf.write(data, 8, len, 'binary');
	} else {
		data.copy(buf, 8, 0, len);
	}
	var crc32 = crc.unsigned(buf.slice(4, 8 + len));
	buf.writeUInt32BE(crc32, len + 8);
	this.chunks.push(buf);
};
github jszoo / cat-mvc / mvc / httpHelper.js View on Github external
wetag: function(body, encoding) {
        if (body.length === 0) {
            // fast-path empty body
            return 'W/"0-0"';
        } else {
            var buf = Buffer.isBuffer(body) ? body : new Buffer(body, encoding);
            return 'W/"' + buf.length.toString(16) + '-' + crc32.unsigned(buf) + '"';
        }
    },
github OrgCurrent / Android / node / express / lib / utils.js View on Github external
exports.wetag = function wetag(body, encoding){
  if (body.length === 0) {
    // fast-path empty body
    return 'W/"0-0"'
  }

  var buf = Buffer.isBuffer(body)
    ? body
    : new Buffer(body, encoding)
  var len = buf.length
  return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'
};
github No9 / harmon / node_modules / connect / node_modules / express-session / index.js View on Github external
function hash(sess) {
  return crc32.signed(JSON.stringify(sess, function(key, val){
    if ('cookie' != key) return val;
  }));
}
github sdslabs / play / node_modules / express / node_modules / connect / lib / middleware / session.js View on Github external
function hash(sess) {
  return crc32.signed(JSON.stringify(sess, function(key, val){
    if ('cookie' != key) return val;
  }));
}

buffer-crc32

A pure javascript CRC32 algorithm that plays nice with binary data

MIT
Latest version published 5 months ago

Package Health Score

78 / 100
Full package analysis

Similar packages