How to use crc32-stream - 5 common examples

To help you get started, we’ve selected a few crc32-stream 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 artem-karpenko / archiver-zip-encrypted / lib / zip20 / zip-crypto-stream.js View on Github external
ZipCryptoStream.prototype._smartStream = function (ae, callback) {
    let deflate = ae.getMethod() === constants.METHOD_DEFLATED;
    let compressionStream = deflate ? new DeflateCRC32Stream(this.options.zlib) : new CRC32Stream();
    let error = null;
    let bufferedData = [];

    compressionStream.once('error', function (err) {
        error = err;
    });

    compressionStream.on('data', (data) => {
        bufferedData.push(data);
    });

    compressionStream.once('end', () => {
        let crc = compressionStream.digest();

        // gather complete information for CRC and sizes
        ae.setCrc(crc.readUInt32BE(0));
github ksoichiro / node-archiver-zip-encryptable / lib / zip-crypto-stream.js View on Github external
ZipCryptoStream.prototype._smartStream = function(ae, callback) {
  var zipCrypto = new ZipCrypto(this.options);
  zipCrypto.init();
  var encryptionHeader = Buffer.from(cryptoRandomString(24), 'hex');
  var encryptedHeader = zipCrypto.encrypt(encryptionHeader);
  var crc = ae.getTimeDos();
  encryptedHeader[10] = crc & 0xff;
  encryptedHeader[11] = (crc >> 8) & 0xff;
  zipCrypto.init();
  var encryptedHeader2 = zipCrypto.encrypt(encryptedHeader);
  this.write(encryptedHeader2);

  var deflate = ae.getMethod() === constants.METHOD_DEFLATED;
  var process = deflate
    ? new DeflateCRC32Stream(this.options.zlib)
    : new CRC32Stream();
  var error = null;

  function handleStuff() {
    var digest = process.digest().readUInt32BE(0);
    ae.setCrc(digest);
    ae.setSize(process.size());
    ae.setCompressedSize(process.size(true) + encryptionHeader.length);
    this._afterAppend(ae);
    callback(error, ae);
  }
  var outStream = new Writable({
    write: function(chunk, encoding, callback) {
      var buffer = zipCrypto.encrypt(chunk);
      this.write(buffer);
      callback();
    }.bind(this)
github ksoichiro / node-archiver-zip-encryptable / lib / zip-crypto-stream.js View on Github external
ZipCryptoStream.prototype._smartStream = function(ae, callback) {
  var zipCrypto = new ZipCrypto(this.options);
  zipCrypto.init();
  var encryptionHeader = Buffer.from(cryptoRandomString(24), 'hex');
  var encryptedHeader = zipCrypto.encrypt(encryptionHeader);
  var crc = ae.getTimeDos();
  encryptedHeader[10] = crc & 0xff;
  encryptedHeader[11] = (crc >> 8) & 0xff;
  zipCrypto.init();
  var encryptedHeader2 = zipCrypto.encrypt(encryptedHeader);
  this.write(encryptedHeader2);

  var deflate = ae.getMethod() === constants.METHOD_DEFLATED;
  var process = deflate
    ? new DeflateCRC32Stream(this.options.zlib)
    : new CRC32Stream();
  var error = null;

  function handleStuff() {
    var digest = process.digest().readUInt32BE(0);
    ae.setCrc(digest);
    ae.setSize(process.size());
    ae.setCompressedSize(process.size(true) + encryptionHeader.length);
    this._afterAppend(ae);
    callback(error, ae);
  }
  var outStream = new Writable({
    write: function(chunk, encoding, callback) {
      var buffer = zipCrypto.encrypt(chunk);
      this.write(buffer);
      callback();
github archiverjs / node-compress-commons / lib / archivers / zip / zip-archive-output-stream.js View on Github external
ZipArchiveOutputStream.prototype._smartStream = function(ae, callback) {
  var deflate = ae.getMethod() === constants.METHOD_DEFLATED;
  var process = deflate ? new DeflateCRC32Stream(this.options.zlib) : new CRC32Stream();
  var error = null;

  function handleStuff() {
    var digest = process.digest().readUInt32BE(0);
    ae.setCrc(digest);
    ae.setSize(process.size());
    ae.setCompressedSize(process.size(true));
    this._afterAppend(ae);
    callback(error, ae);
  }

  process.once('end', handleStuff.bind(this));
  process.once('error', function(err) {
    error = err;
  });
github artem-karpenko / archiver-zip-encrypted / lib / aes / zip-aes-stream.js View on Github external
ZipAesStream.prototype._smartStream = function (ae, callback) {
    var deflate = ae.getExtra().readInt16LE(9) > 0;
    var compressionStream = deflate ? new DeflateCRC32Stream(this.options.zlib) : new CRC32Stream();
    var encryptionStream = new AesHmacEtmStream({key: this.key, salt: this.options.salt});
    var error = null;

    function onEnd() {
        var digest = compressionStream.digest().readUInt32BE(0);
        ae.setCrc(digest);
        ae.setSize(compressionStream.size());
        ae.setCompressedSize(encryptionStream.getTotalSize());
        this._afterAppend(ae);
        callback(error, ae);
    }

    encryptionStream.once('end', onEnd.bind(this));
    compressionStream.once('error', function (err) {
        error = err;
    });

crc32-stream

a streaming CRC32 checksumer

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis