Esempio n. 1
0
Download.prototype.construct = function( files ) {
	var stream = through.obj();

	files.forEach( function( file ) {
		var obj = new File( file );
		obj.url = file.url;
		stream.write( obj );
	} );

	stream.end();

	if( this.opts.extract ) {
		this.tasks.unshift( tar( this.opts ), tarBz2( this.opts ), tarGz( this.opts ), zip( this.opts ) );
	}

	this.tasks.unshift( stream );

	if( this.rename() ) {
		this.tasks.push( rename( this.rename() ) );
	}

	if( this.dest() ) {
		this.tasks.push( fs.dest( this.dest(), this.opts ) );
	}

	return combine( this.tasks );
};
Esempio n. 2
0
module.exports = async function getZonetab(...args) {
	const argLen = args.length;

	if (argLen > 1) {
		throw new RangeError(`Expected 0 or 1 argument (<Object>), but got ${argLen} arguments.`);
	}

	const [options] = args;

	const response = await fettuccine('time-zones/repository/tzdata-latest.tar.gz', {
		baseUrl: 'https://www.iana.org/',
		...options,
		encoding: null
	});

	if (response.statusCode < 200 || 299 < response.statusCode) {
		throw new Error(`${response.statusCode} ${response.statusMessage}`);
	}

	const data = (await decompressTargz()(response.body)).find(isZoneTab).data;
	const encoding = {encoding: 'utf8', ...options}.encoding;

	if (encoding !== null) {
		return data.toString(encoding);
	}

	return data;
};
Esempio n. 3
0
module.exports = (input, output, opts) => {
	if (typeof input !== 'string' && !Buffer.isBuffer(input)) {
		return Promise.reject(new TypeError('Input file required'));
	}

	if (typeof output === 'object') {
		opts = output;
		output = null;
	}

	opts = Object.assign({plugins: [
		decompressTar(),
		decompressTarbz2(),
		decompressTargz(),
		decompressUnzip()
	]}, opts);

	const read = typeof input === 'string' ? fsP.readFile(input) : Promise.resolve(input);

	return read.then(buf => extractFile(buf, output, opts));
};