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

gulp-vinyl-zip

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-vinyl-zip - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

175

lib/src/index.js

@@ -6,2 +6,3 @@ 'use strict';

var through = require('through2');
var es = require('event-stream');
var File = require('../vinyl-zip');

@@ -22,89 +23,127 @@ var queue = require('queue');

function src(zipPath) {
var stream = through.obj();
function toStream(zip) {
var result = es.through();
var q = queue();
var didErr = false;
yauzl.open(zipPath, function (err, zip) {
if (err) {
return stream.emit('error', err);
}
q.on('error', function (err) {
didErr = true;
result.emit('error', err);
});
var q = queue();
var didErr = false;
zip.on('entry', function (entry) {
if (didErr) { return; }
q.on('error', function (err) {
didErr = true;
stream.emit('error', err);
});
var stat = new fs.Stats();
stat.mode = modeFromEntry(entry);
stat.mtime = mtimeFromEntry(entry);
zip.on('entry', function (entry) {
if (didErr) { return; }
var file = {
path: entry.fileName,
stat: stat
};
var stat = new fs.Stats();
stat.mode = modeFromEntry(entry);
stat.mtime = mtimeFromEntry(entry);
if (stat.isFile()) {
if (entry.uncompressedSize === 0) {
file.contents = new Buffer(0);
result.emit('data', new File(file));
} else {
q.push(function (cb) {
zip.openReadStream(entry, function(err, readStream) {
if (err) { return cb(err); }
var file = {
path: entry.fileName,
stat: stat
};
file.contents = readStream;
result.emit('data', new File(file));
cb();
});
});
q.start();
}
if (stat.isFile()) {
if (entry.uncompressedSize === 0) {
file.contents = new Buffer(0);
stream.write(new File(file));
} else {
q.push(function (cb) {
zip.openReadStream(entry, function(err, readStream) {
if (err) { return cb(err); }
} else if (stat.isSymbolicLink()) {
q.push(function (cb) {
zip.openReadStream(entry, function(err, readStream) {
if (err) { return cb(err); }
file.contents = readStream;
stream.write(new File(file));
cb();
});
file.symlink = '';
readStream.on('data', function(c) { file.symlink += c });
readStream.on('error', cb);
readStream.on('end', function () {
result.emit('data', new File(file));
cb();
});
q.start();
}
});
});
} else if (stat.isSymbolicLink()) {
q.push(function (cb) {
zip.openReadStream(entry, function(err, readStream) {
if (err) { return cb(err); }
q.start();
file.symlink = '';
readStream.on('data', function(c) { file.symlink += c });
readStream.on('error', cb);
readStream.on('end', function () {
stream.write(new File(file));
cb();
});
});
});
} else {
result.emit('data', new File(file));
}
});
q.start();
zip.on('end', function() {
if (didErr) {
return;
}
} else {
stream.write(new File(file));
}
});
if (q.length === 0) {
result.end();
} else {
q.on('end', function () {
result.end();
});
}
});
return result;
}
zip.on('end', function() {
if (didErr) {
return;
}
function unzipBuffer(contents) {
var result = es.through();
yauzl.fromBuffer(contents, function (err, zip) {
if (err) { return result.emit('error', err); }
toStream(zip).pipe(result);
});
return result;
}
if (q.length === 0) {
stream.end();
} else {
q.on('end', function () {
stream.end();
});
}
});
function unzipFile(zipPath) {
var result = es.through();
yauzl.open(zipPath, function (err, zip) {
if (err) { return result.emit('error', err); }
toStream(zip).pipe(result);
});
return result;
}
return stream;
function unzip() {
var input = es.through();
var result = es.through();
var zips = [];
var output = input.pipe(es.through(function (f) {
if (!f.isBuffer()) {
this.emit('error', new Error('Only supports buffers'));
}
zips.push(f);
}, function () {
var streams = zips.map(function (f) {
return unzipBuffer(f.contents);
});
es.merge(streams).pipe(result);
this.emit('end');
}));
return es.duplex(input, es.merge(output, result));
}
function src(zipPath) {
return zipPath ? unzipFile(zipPath) : unzip();
}
module.exports = src;
{
"name": "gulp-vinyl-zip",
"version": "1.0.8",
"version": "1.1.0",
"description": "Streaming vinyl adapter for zip archives",

@@ -30,2 +30,3 @@ "main": "index.js",

"dependencies": {
"event-stream": "^3.3.1",
"queue": "^3.0.10",

@@ -32,0 +33,0 @@ "through2": "^0.6.3",

@@ -23,2 +23,16 @@ # gulp-vinyl-zip

or
```javascript
var gulp = require('gulp');
var zip = require('gulp-vinyl-zip');
gulp.task('default', function () {
return gulp.src('src.zip')
.pipe(zip.src())
.pipe(/* knock yourself out */)
.pipe(zip.dest('out.zip'));
});
```
**Archive → File System**

@@ -25,0 +39,0 @@

@@ -25,2 +25,16 @@ 'use strict';

});
it('src should be able to read from archives in streams', function (cb) {
var count = 0;
vfs.src(path.join(__dirname, 'assets', '*.zip'))
.pipe(lib.src())
.pipe(through.obj(function(chunk, enc, cb) {
count++;
cb();
}, function () {
assert.equal(7, count);
cb();
}));
});

@@ -27,0 +41,0 @@ it('dest should be able to create an archive from another archive', function (cb) {

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