download.run(function (err, files) { t.assert(!err, err); t.assert(scope.isDone()); t.assert(files.length === 2); t.assert(files[0].path === 'test-file.zip'); t.assert(files[0].url === 'http://foo.com/test-file.zip'); t.assert(archiveType(files[0].contents) === 'zip'); t.assert(files[1].path === 'test-file.zip'); t.assert(files[1].url === 'http://foo.com/nested/test-file.zip'); t.assert(archiveType(files[1].contents) === 'zip'); });
.on('end', function () { files.push({ url: obj.url, contents: Buffer.concat(ret) }); if (!obj.dest) { done(); return; } if (obj.opts.extract && archiveType(Buffer.concat(ret))) { return self._extract(Buffer.concat(ret), obj.dest, obj.opts, function (err) { if (err) { done(err); return; } done(); }); } self._write(Buffer.concat(ret), path.join(obj.dest, name), obj.opts, function (err) { if (err) { done(err); return; } done(); }); });
download.run(function (err, files) { t.assert(!err, err); t.assert(scope.isDone()); t.assert(path.basename(files[0].path) === 'foobar.zip'); t.assert(archiveType(files[0].contents) === 'zip'); t.assert(files[0].url === 'http://foo.com/test-file.zip'); });
return through.obj(function (file, enc, cb) { var self = this; if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { cb(new gutil.PluginError('gulp-decompress', 'Streaming is not supported')); return; } if (!archiveType(file.contents)) { cb(null, file); return; } var decompress = new Decompress() .src(file.contents) .use(Decompress.tar(opts)) .use(Decompress.tarbz2(opts)) .use(Decompress.targz(opts)) .use(Decompress.zip(opts)); decompress.run(function (err, files) { if (err) { cb(new gutil.PluginError('gulp-decompress:', err, { fileName: file.path })); return; } files.forEach(self.push.bind(self)); cb(); }); });
read(this.src(), function (err, data) { if (err && err.code !== 'EISDIR') { cb(err); return; } if (archiveType(data)) { return self.decompress(function (err) { if (err) { cb(err); return; } self.exec(self._tmp, cb); }); } self.exec(self.src(), cb); });
module.exports = opts => new Transform({ objectMode: true, transform(file, enc, cb) { if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { cb(new PluginError('gulp-decompress', 'Streaming is not supported')); return; } if (!archiveType(file.contents)) { cb(null, file); return; } decompress(file.contents, opts) .then(files => { for (const x of files) { const stat = new fs.Stats(); stat.mode = x.mode; stat.mtime = x.mtime; stat.isDirectory = () => x.type === 'directory'; this.push(new Vinyl({ stat, contents: stat.isDirectory() ? null : x.data, path: x.path })); } cb(); }) .catch(err => { cb(new PluginError('gulp-decompress:', err, {fileName: file.path})); }); } });
return function (file, decompress, cb) { var files = []; if (archiveType(file.contents) !== 'tar') { return cb(); } sbuff(file.contents).pipe(tar.Parse()) .on('error', function (err) { return cb(err); }) .on('entry', function (file) { var chunk = ''; file.on('data', function (data) { chunk += data.toString(); }); file.on('end', function () { chunk = new Buffer(chunk, 'utf8'); if (opts.strip) { var f = path.basename(file.path); var p = path.dirname(file.path.split('/')); if (Array.isArray(p)) { p = p.slice(opts.strip).join(path.sep); } file.path = path.join(p, f); } files.push({ contents: chunk, path: file.path }); }); }) .on('end', function () { decompress.files = files; cb(); }); };
return function (file, decompress, cb) { var files = []; if (archiveType(file.contents) !== 'zip') { return cb(); } tempWrite(file.contents, function (err, filepath) { var zip = new Zip(filepath); zip.getEntries().forEach(function (file) { if (!file.isDirectory) { file.path = file.entryName.toString(); if (opts.strip) { var f = path.basename(file.path); var p = path.dirname(file.path.split('/')); if (Array.isArray(p)) { p = p.slice(opts.strip).join(path.sep); } file.path = path.join(p, f); } files.push({ contents: file.getData(), path: file.path }); } }); decompress.files = files; rm(filepath, function (err) { if (err) { return cb(err); } cb(); }); }); };