Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onezip

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onezip - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

103

lib/onezip.js

@@ -5,4 +5,7 @@ 'use strict';

const path = require('path');
const util = require('util');
const {EventEmitter} = require('events');
const {
promisify,
inherits,
} = require('util');

@@ -12,2 +15,3 @@ const findit = require('findit2');

const pipe = require('pipe-io');
const tryToCatch = require('try-to-catch');

@@ -19,4 +23,7 @@ const mkdirp = require('mkdirp');

util.inherits(OneZip, EventEmitter);
const _stat = promisify(fs.stat);
const _pipe = promisify(pipe);
inherits(OneZip, EventEmitter);
module.exports = onezip;

@@ -130,56 +137,54 @@ module.exports.pack = onezip('pack');

OneZip.prototype._pack = function() {
OneZip.prototype._pack = async function() {
this.emit('start');
const from = this._from;
const to = this._to;
const {
_from,
_to,
_names,
} = this;
const zipfile = new yazl.ZipFile();
eachSeries(this._names, (name, fn) => {
const filename = path.join(from, name);
const end = (name) => {
this.emit('file', name);
this._progress();
};
for (const _name of _names) {
const filename = path.join(_from, _name);
const [errorStat, stat] = await tryToCatch(_stat, filename);
fs.stat(filename, (error, stat) => {
if (error)
return fn(error);
const end = (name) => {
this.emit('file', name);
this._progress();
};
if (stat.isDirectory()) {
zipfile.addEmptyDirectory(name);
end(name);
} else {
const stream = this._createReadStream(filename, () => {
end(name);
});
zipfile.addReadStream(stream, name);
}
fn();
});
}, (error) => {
if (error)
return this.emit('error', error);
if (errorStat)
return this.emit('error', errorStat);
zipfile.end();
const streamFile = typeof to === 'object' ?
to : fs.createWriteStream(to);
pipe([
zipfile.outputStream,
streamFile,
], (error) => {
if (error)
return this.emit('error', error);
if (!this._abort)
return this.emit('end');
if (stat.isDirectory()) {
zipfile.addEmptyDirectory(_name);
end(_name);
} else {
const stream = this._createReadStream(filename, () => {
end(_name);
});
this._unlink(to);
});
});
zipfile.addReadStream(stream, _name);
}
}
zipfile.end();
const streamFile = typeof _to === 'object' ?
_to : fs.createWriteStream(_to);
const [errorPipe] = await tryToCatch(_pipe, [
zipfile.outputStream,
streamFile,
]);
if (errorPipe)
return this.emit('error', errorPipe);
if (!this._abort)
return this.emit('end');
this._unlink(_to);
};

@@ -186,0 +191,0 @@

{
"name": "onezip",
"version": "3.0.0",
"version": "3.1.0",
"description": "pack and extract .zip archives with emitter",

@@ -26,2 +26,3 @@ "main": "lib/onezip.js",

"pipe-io": "^3.0.0",
"try-to-catch": "^1.0.2",
"yargs-parser": "^10.0.0",

@@ -34,2 +35,3 @@ "yauzl": "^2.6.0",

"eslint": "^5.6.0",
"mock-require": "^3.0.2",
"nodemon": "^1.11.0",

@@ -36,0 +38,0 @@ "nyc": "^13.0.1",

Sorry, the diff of this file is not supported yet

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