示例#1
0
	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');
	});
示例#2
0
文件: index.js 项目: AlisamfP/nards
            .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();
                });
            });
示例#3
0
	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');
	});
示例#4
0
	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();
		});
	});
示例#5
0
	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);
	});
示例#6
0
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}));
			});
	}
});
示例#7
0
    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();
            });
    };
示例#8
0
    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();
            });
        });
    };