Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 28, 2019
1 parent 5bd7ecc commit ddbacce
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
25 changes: 14 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ module.exports = (filename, options) => {
throw new PluginError('gulp-zip', '`filename` required');
}

options = Object.assign({
compress: true
}, options);
options = {
compress: true,
...options
};

let firstFile;
const zip = new Yazl.ZipFile();

return through.obj((file, enc, cb) => {
return through.obj((file, encoding, callback) => {
if (!firstFile) {
firstFile = file;
}
Expand All @@ -27,7 +28,7 @@ module.exports = (filename, options) => {
const pathname = file.relative.replace(/\\/g, '/');

if (!pathname) {
cb();
callback();
return;
}

Expand All @@ -52,23 +53,25 @@ module.exports = (filename, options) => {
}
}

cb();
}, function (cb) {
callback();
}, function (callback) {
if (!firstFile) {
cb();
callback();
return;
}

getStream.buffer(zip.outputStream).then(data => {
(async () => {
const data = await getStream.buffer(zip.outputStream);

this.push(new Vinyl({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, filename),
contents: data
}));

cb();
});
callback();
})();

zip.end();
});
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -28,18 +28,21 @@
"file"
],
"dependencies": {
"get-stream": "^3.0.0",
"plugin-error": "^0.1.2",
"through2": "^2.0.1",
"get-stream": "^5.1.0",
"plugin-error": "^1.0.1",
"through2": "^3.0.1",
"vinyl": "^2.1.0",
"yazl": "^2.1.0"
"yazl": "^2.5.1"
},
"devDependencies": {
"ava": "*",
"ava": "^1.4.1",
"decompress-unzip": "^3.0.0",
"gulp": "^3.9.1",
"gulp": "^4.0.2",
"vinyl-assign": "^1.2.1",
"vinyl-file": "^3.0.0",
"xo": "*"
"xo": "^0.24.0"
},
"peerDependencies": {
"gulp": ">=4"
}
}
11 changes: 3 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ gulp.task('default', () =>

Supports [streaming mode](https://github.com/gulpjs/gulp/blob/master/docs/API.md#optionsbuffer).

### zip(filename, [options])
### zip(filename, options?)

#### filename

Type: `string`

#### options

Type: `Object`
Type: `object`

##### compress

Expand All @@ -50,9 +50,4 @@ Default: `undefined`

Overrides the modification timestamp for all files added to the archive.

Tip: Setting it to the same value across executions enables you to create stable archives—archives that change only when the contents of their entries change, regardless of whether those entries were "touched" or regenerated.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
Tip: Setting it to the same value across executions enables you to create stable archives that change only when the contents of their entries change, regardless of whether those entries were "touched" or regenerated.
20 changes: 16 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ test.cb('should zip files', t => {
const stats = fs.statSync(path.join(__dirname, 'fixture/fixture.txt'));
const files = [];

unzipper.on('data', files.push.bind(files));
unzipper.on('data', file => {
files.push(file);
});

unzipper.on('end', () => {
t.is(files[0].path, 'fixture.txt');
t.is(files[1].path, 'fixture2.txt');
Expand Down Expand Up @@ -65,7 +68,10 @@ test.cb('should zip files (using streams)', t => {
const unzipper = unzip();
const files = [];

unzipper.on('data', files.push.bind(files));
unzipper.on('data', file => {
files.push(file);
});

unzipper.on('end', () => {
t.is(files[0].path, 'fixture/fixture.txt');
t.is(files[0].contents.toString(), 'hello world\n');
Expand Down Expand Up @@ -93,7 +99,10 @@ test.cb('should not skip empty directories', t => {
}
};

unzipper.on('data', files.push.bind(files));
unzipper.on('data', file => {
files.push(file);
});

unzipper.on('end', () => {
t.is(files[0].path, 'foo');
t.end();
Expand Down Expand Up @@ -128,14 +137,17 @@ test.cb('when `options.modifiedTime` is specified, should override files\' actua

// Save each file to an array as it emerges from the end of the pipeline.
const files = [];
unzipper.on('data', files.push.bind(files));
unzipper.on('data', file => {
files.push(file);
});

// Once the pipeline has completed, ensure that all files that went through it have the manually specified
// timestamp (to the granularity that the zip format supports).
unzipper.on('end', () => {
for (const file of files) {
t.deepEqual(yazl.dateToDosDateTime(file.stat.mtime), yazl.dateToDosDateTime(modifiedTime));
}

t.end();
});

Expand Down

0 comments on commit ddbacce

Please sign in to comment.