Socket
Socket
Sign inDemoInstall

zip-stream

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip-stream - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

17

lib/util/DeflateRawChecksum.js

@@ -18,3 +18,2 @@ /**

this.checksum.writeInt32BE(0, 0);
this.digest = 0;

@@ -32,6 +31,2 @@ this.rawSize = 0;

}
this.once('end', function() {
this.digest = crc32.unsigned(0, this.checksum);
});
}

@@ -58,2 +53,14 @@

DeflateRawChecksum.prototype.digest = function() {
return crc32.unsigned(0, this.checksum);
};
DeflateRawChecksum.prototype.hex = function() {
return this.digest().toString(16).toUpperCase();
};
DeflateRawChecksum.prototype.size = function() {
return this.rawSize;
};
module.exports = DeflateRawChecksum;

@@ -10,4 +10,6 @@ /**

var path = require('path');
var stream = require('stream');
var Stream = require('stream').Stream;
var PassThrough = require('readable-stream').PassThrough;
var loDefaults = require('lodash.defaults');

@@ -78,5 +80,20 @@

util.isStream = function(source) {
return (source instanceof stream.Stream);
return source instanceof Stream;
};
util.normalizeInputSource = function(source) {
if (source === null) {
return new Buffer(0);
} else if (typeof source === 'string') {
return new Buffer(source);
} else if (util.isStream(source) && !source._readableState) {
var normalized = new PassThrough();
source.pipe(normalized);
return normalized;
}
return source;
};
util.sanitizePath = function() {

@@ -83,0 +100,0 @@ var filepath = path.join.apply(path, arguments);

@@ -9,7 +9,7 @@ /**

var inherits = require('util').inherits;
var Transform = require('stream').Transform || require('readable-stream').Transform;
var PassThrough = require('stream').PassThrough || require('readable-stream').PassThrough;
var Transform = require('readable-stream').Transform;
var PassThrough = require('readable-stream').PassThrough;
var crc32 = require('buffer-crc32');
var ChecksumStream = require('./util/ChecksumStream');
var ChecksumStream = require('crc32-stream');
var DeflateRawChecksum = require('./util/DeflateRawChecksum');

@@ -54,3 +54,3 @@ var headers = require('./headers');

this.offset = 0;
this.files = [];
this.entries = [];

@@ -62,2 +62,3 @@ this._finalize = false;

this.once('end', function() {
debug('stats:' + this.entries.length + 'e:' + this.offset + 'b');
debug('end');

@@ -69,6 +70,6 @@ });

ZipStream.prototype._afterAppend = function(file) {
debugEntry('%s:finish', file.name);
ZipStream.prototype._afterAppend = function(entry) {
debugEntry('%s:finish', entry.name);
this.files.push(file);
this.entries.push(entry);
this._processing = false;

@@ -110,9 +111,10 @@

} else {
var processStream = self._newProcessStream(data.store);
processStream.once('error', callback);
var processStream = self._newProcessStream(data.store, function(err) {
if (err) {
return callback(err);
}
processStream.once('end', function() {
data.crc32 = processStream.digest;
data.uncompressedSize = processStream.rawSize;
data.compressedSize = processStream.compressedSize || processStream.rawSize;
data.crc32 = processStream.digest();
data.uncompressedSize = processStream.size();
data.compressedSize = processStream.compressedSize || data.uncompressedSize;

@@ -122,4 +124,2 @@ onend();

processStream.pipe(self, { end: false });
processStream.end(source);

@@ -136,23 +136,16 @@ }

function onend() {
var processStream = self._newProcessStream(data.store, function(err) {
if (err) {
return callback(err);
}
data.crc32 = processStream.digest();
data.uncompressedSize = processStream.size();
data.compressedSize = processStream.compressedSize || data.uncompressedSize;
self.write(headers.encode('fileDescriptor', data));
self._afterAppend(data);
callback(null, data);
}
var processStream = self._newProcessStream(data.store);
processStream.once('error', callback);
processStream.once('end', function() {
data.crc32 = processStream.digest;
data.uncompressedSize = processStream.rawSize;
data.compressedSize = processStream.compressedSize || processStream.rawSize;
onend();
});
processStream.pipe(self, { end: false });
source.pipe(processStream);

@@ -167,3 +160,3 @@ };

ZipStream.prototype._newProcessStream = function(store) {
ZipStream.prototype._newProcessStream = function(store, callback) {
var process;

@@ -177,2 +170,9 @@

if (typeof callback === 'function') {
process.once('error', callback);
process.once('end', callback);
}
process.pipe(this, { end: false });
return process;

@@ -219,17 +219,2 @@ };

ZipStream.prototype._normalizeSource = function(source) {
if (source === null) {
return new Buffer(0);
} else if (typeof source === 'string') {
return new Buffer(source);
} else if (util.isStream(source) && !source._readableState) {
var normalized = new PassThrough();
source.pipe(normalized);
return normalized;
}
return source;
};
ZipStream.prototype._transform = function(chunk, encoding, callback) {

@@ -240,3 +225,3 @@ callback(null, chunk);

ZipStream.prototype._writeCentralDirectory = function() {
var files = this.files;
var entries = this.entries;
var comment = this.options.comment;

@@ -247,6 +232,6 @@ var cdoffset = this.offset;

var centralDirectoryBuffer;
for (var i = 0; i < files.length; i++) {
var file = files[i];
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
centralDirectoryBuffer = headers.encode('centralDirectory', file);
centralDirectoryBuffer = headers.encode('centralDirectory', entry);
this.write(centralDirectoryBuffer);

@@ -257,4 +242,4 @@ cdsize += centralDirectoryBuffer.length;

var centralDirectoryFooterData = {
directoryRecordsDisk: files.length,
directoryRecords: files.length,
directoryRecordsDisk: entries.length,
directoryRecords: entries.length,
centralDirectorySize: cdsize,

@@ -297,3 +282,3 @@ centralDirectoryOffset: cdoffset,

this._processing = true;
source = this._normalizeSource(source);
source = util.normalizeInputSource(source);

@@ -300,0 +285,0 @@ if (Buffer.isBuffer(source)) {

{
"name": "zip-stream",
"version": "0.3.1",
"description": "a streaming zip generator.",
"version": "0.3.2",
"description": "a streaming zip archive generator.",
"homepage": "https://github.com/ctalkington/node-zip-stream",

@@ -24,2 +24,6 @@ "author": {

"main": "lib/zip-stream.js",
"files": [
"lib",
"LICENSE-MIT"
],
"engines": {

@@ -32,2 +36,3 @@ "node": ">= 0.8.0"

"dependencies": {
"crc32-stream": "~0.2.0",
"readable-stream": "~1.0.24",

@@ -34,0 +39,0 @@ "lodash.defaults": "~2.4.1",

@@ -1,4 +0,4 @@

# zip-stream v0.3.1 [![Build Status](https://travis-ci.org/ctalkington/node-zip-stream.svg?branch=master)](https://travis-ci.org/ctalkington/node-zip-stream)
# zip-stream v0.3.2 [![Build Status](https://travis-ci.org/ctalkington/node-zip-stream.svg?branch=master)](https://travis-ci.org/ctalkington/node-zip-stream)
zip-stream is a streaming zip generator. It was built to be a successor to [zipstream](https://npmjs.org/package/zipstream). Dependencies are kept to a minimum through the use of many of node's built-in modules including the use of zlib module for compression.
zip-stream is a streaming zip archive generator. It was built to be a successor to [zipstream](https://npmjs.org/package/zipstream). Dependencies are kept to a minimum through the use of many of node's built-in modules including the use of zlib module for compression.

@@ -43,3 +43,3 @@ [![NPM](https://nodei.co/npm/zip-stream.png)](https://nodei.co/npm/zip-stream/)

#### entry(input, data, callback(err, entry))
#### entry(input, data, callback(err, data))

@@ -115,3 +115,3 @@ Appends an input source (text string, buffer, or stream) to the instance. When the instance has received, processed, and emitted the input, the callback is fired.

- [Changelog](https://github.com/ctalkington/node-zip-stream/releases)
- [Releases](https://github.com/ctalkington/node-zip-stream/releases)
- [Contributing](https://github.com/ctalkington/node-zip-stream/blob/master/CONTRIBUTING.md)

@@ -118,0 +118,0 @@ - [MIT License](https://github.com/ctalkington/node-zip-stream/blob/master/LICENSE-MIT)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc