How to use the buffer-crc32.unsigned function in buffer-crc32

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 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 archiverjs / node-compress-commons / lib / archivers / zip / zip-archive-output-stream.js View on Github external
ZipArchiveOutputStream.prototype._appendBuffer = function(ae, source, callback) {
  if (source.length === 0) {
    ae.setMethod(constants.METHOD_STORED);
  }

  var method = ae.getMethod();

  if (method === constants.METHOD_STORED) {
    ae.setSize(source.length);
    ae.setCompressedSize(source.length);
    ae.setCrc(crc32.unsigned(source));
  }

  this._writeLocalFileHeader(ae);

  if (method === constants.METHOD_STORED) {
    this.write(source);
    this._afterAppend(ae);
    callback(null, ae);
    return;
  } else if (method === constants.METHOD_DEFLATED) {
    this._smartStream(ae, callback).end(source);
    return;
  } else {
    callback(new Error('compression method ' + method + ' not implemented'));
    return;
  }
github GMOD / cram-js / src / cramFile / file.js View on Github external
async checkCrc32(position, length, recordedCrc32, description) {
    const b = Buffer.allocUnsafe(length)
    await this.file.read(b, 0, length, position)
    const calculatedCrc32 = crc32.unsigned(b)
    if (calculatedCrc32 !== recordedCrc32) {
      throw new CramMalformedError(
        `crc mismatch in ${description}: recorded CRC32 = ${recordedCrc32}, but calculated CRC32 = ${calculatedCrc32}`,
      )
    }
  }
github appcelerator / titanium_mobile / node_modules / compress-commons / lib / archivers / zip / zip-archive-output-stream.js View on Github external
ZipArchiveOutputStream.prototype._appendBuffer = function(ae, source, callback) {
  if (source.length === 0) {
    ae.setMethod(constants.METHOD_STORED);
  }

  var method = ae.getMethod();

  if (method === constants.METHOD_STORED) {
    ae.setSize(source.length);
    ae.setCompressedSize(source.length);
    ae.setCrc(crc32.unsigned(source));
  }

  this._writeLocalFileHeader(ae);

  if (method === constants.METHOD_STORED) {
    this.write(source);
    this._afterAppend(ae);
    callback(null, ae);
    return;
  } else if (method === constants.METHOD_DEFLATED) {
    this._smartStream(ae, callback).end(source);
    return;
  } else {
    callback(new Error('compression method ' + method + ' not implemented'));
    return;
  }
github archiverjs / node-archiver / lib / plugins / json.js View on Github external
function onend(err, sourceBuffer) {
    if (err) {
      callback(err);
      return;
    }

    data.size = sourceBuffer.length || 0;
    data.crc32 = crc32.unsigned(sourceBuffer);

    self.files.push(data);

    callback(null, data);
  }

buffer-crc32

A pure javascript CRC32 algorithm that plays nice with binary data

MIT
Latest version published 3 months ago

Package Health Score

80 / 100
Full package analysis

Similar packages