How to use the crc32-stream.CRC32Stream function in crc32-stream

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 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)

crc32-stream

a streaming CRC32 checksumer

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis