Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ZipCryptoStream.prototype._appendStream = function(ae, source, callback) {
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
ae.getGeneralPurposeBit().useDataDescriptor(false);
// we will write local file header after we get CRC back
// it seems as if using data descriptor is not supported when encrypting data with ZipCrypto
// so we have to write CRC into local file header
// this._writeLocalFileHeader(ae);
var smart = this._smartStream(ae, callback);
source.once('error', function(err) {
smart.emit('error', err);
smart.end();
});
source.pipe(smart);
};
ZipCryptoStream.prototype._appendBuffer = function(ae, source, callback) {
ae.gpb.useEncryption(true);
// Use data descriptor whatever the method is,
// because when using encryption, we need to calculate
// the compressed size with encrypted data.
ae.gpb.useDataDescriptor(true);
ae.setVersionNeededToExtract(constants.MIN_VERSION_DATA_DESCRIPTOR);
if (source.length === 0) {
ae.setMethod(constants.METHOD_STORED);
}
this._writeLocalFileHeader(ae);
var method = ae.getMethod();
if (
method === constants.METHOD_STORED ||
method === constants.METHOD_DEFLATED
) {
this._smartStream(ae, callback).end(source);
} else {
callback(new Error('compression method ' + method + ' not implemented'));
}