Socket
Socket
Sign inDemoInstall

download

Package Overview
Dependencies
236
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 4.0.1-rc.1

license

17

cli.js

@@ -9,6 +9,2 @@ #!/usr/bin/env node

/**
* Options
*/
var cli = meow({

@@ -51,10 +47,2 @@ help: [

/**
* Run
*
* @param {Array} src
* @param {String} dest
* @api private
*/
function run(src, dest) {

@@ -66,3 +54,2 @@ var download = new Download(cli.flags);

if (process.stdout.isTTY) {
download.use(progress());
download.dest(dest);

@@ -85,6 +72,2 @@ }

/**
* Apply arguments
*/
if (process.stdin.isTTY) {

@@ -91,0 +74,0 @@ var src = cli.input;

179

index.js
'use strict';
var combine = require('stream-combiner');
var concat = require('concat-stream');
var conf = require('rc')('npm');
var each = require('each-async');
var combine = require('stream-combiner2');
var concatStream = require('concat-stream');
var decompress = require('gulp-decompress');
var eachAsync = require('each-async');
var File = require('vinyl');
var fs = require('vinyl-fs');
var got = require('got');
var path = require('path');
var rename = require('gulp-rename');
var tar = require('decompress-tar');
var tarBz2 = require('decompress-tarbz2');
var tarGz = require('decompress-targz');
var through = require('through2');
var urlRegex = require('url-regex');
var Ware = require('ware');
var zip = require('decompress-unzip');
var vfs = require('vinyl-fs');

@@ -32,15 +28,2 @@ /**

this.opts = opts || {};
this.opts.strictSSL = conf['strict-ssl'];
this.opts.proxy = conf['https-proxy'] ||
conf['http-proxy'] ||
conf.proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy ||
this.opts.proxy;
this.tasks = [];
this.ware = new Ware();
this._get = [];
}

@@ -52,6 +35,7 @@

* @param {String} url
* @param {String} dest
* @api public
*/
Download.prototype.get = function (url) {
Download.prototype.get = function (url, dest) {
if (!arguments.length) {

@@ -61,3 +45,8 @@ return this._get;

this._get.push(url);
this._get = this._get || [];
this._get.push({
url: url,
dest: dest
});
return this;

@@ -91,6 +80,6 @@ };

if (!arguments.length) {
return this._name;
return this._rename;
}
this._name = name;
this._rename = name;
return this;

@@ -100,26 +89,2 @@ };

/**
* Add a plugin to the middleware stack
*
* @param {Function} plugin
* @api public
*/
Download.prototype.use = function (plugin) {
this.ware.use(plugin);
return this;
};
/**
* Add a task to the middleware stack
*
* @param {Function} task
* @api public
*/
Download.prototype.pipe = function (task) {
this.tasks.push(task);
return this;
};
/**
* Run

@@ -133,9 +98,6 @@ *

cb = cb || function () {};
var request = require('request');
var self = this;
var files = [];
each(this.get(), function (url, i, done) {
if (!urlRegex().test(url)) {
eachAsync(this.get(), function (get, i, done) {
if (!urlRegex().test(get.url)) {
done(new Error('Specify a valid URL'));

@@ -145,16 +107,21 @@ return;

request.get(url, self.opts)
.on('response', function (res) {
self.res(url, res, function (err, ret) {
if (err) {
done(err);
return;
}
got(get.url, {encoding: null}, function (err, data) {
if (err) {
done(err);
return;
}
files.push(ret);
done();
var dest = get.dest || this.dest();
var stream = this.createStream(this.createFile(get.url, data), dest);
stream.on('error', cb);
stream.pipe(concatStream(function (items) {
items.forEach(function (item) {
files.push(item);
});
})
.on('error', done);
}, function (err) {
done();
}));
}.bind(this));
}.bind(this), function (err) {
if (err) {

@@ -165,9 +132,3 @@ cb(err);

var pipe = self.construct(files);
var end = concat(function (files) {
cb(null, files, pipe);
});
pipe.on('error', cb);
pipe.pipe(end);
cb(null, files);
});

@@ -177,76 +138,46 @@ };

/**
* Handle response
* Create vinyl file
*
* @param {String} url
* @param {Object} res
* @param {Function} cb
* @param {Buffer} data
* @api private
*/
Download.prototype.res = function (url, res, cb) {
var ret = [];
var len = 0;
if (res.statusCode < 200 || res.statusCode >= 300) {
var err = new Error([
'Couldn\'t connect to ' + url,
'(' + res.statusCode + ')'
].join(' '));
err.code = res.statusCode;
res.destroy();
cb(err);
return;
}
res.on('error', cb);
res.on('data', function (data) {
ret.push(data);
len += data.length;
Download.prototype.createFile = function (url, data) {
var obj = new File({
contents: data,
path: path.basename(url)
});
this.ware.run(res, url);
res.on('end', function () {
cb(null, {
path: path.basename(url),
contents: Buffer.concat(ret, len),
url: url
});
});
obj.url = url;
return obj;
};
/**
* Construct stream
* Create stream
*
* @param {Array} files
* @param {Object} file
* @param {String} dest
* @api private
*/
Download.prototype.construct = function (files) {
Download.prototype.createStream = function (file, dest) {
var stream = through.obj();
var streams = [stream];
files.forEach(function (file) {
var obj = new File(file);
obj.url = file.url;
stream.write(obj);
});
stream.end(file);
stream.end();
if (this.opts.extract) {
this.tasks.unshift(tar(this.opts), tarBz2(this.opts), tarGz(this.opts), zip(this.opts));
streams.push(decompress(this.opts));
}
this.tasks.unshift(stream);
if (this.rename()) {
this.tasks.push(rename(this.rename()));
streams.push(rename(this.rename()));
}
if (this.dest()) {
this.tasks.push(fs.dest(this.dest(), this.opts));
if (dest) {
streams.push(vfs.dest(dest, this.opts));
}
return combine(this.tasks);
return combine(streams);
};

@@ -253,0 +184,0 @@

{
"name": "download",
"version": "3.3.0",
"version": "4.0.1-rc.1",
"description": "Download and extract files effortlessly",

@@ -34,27 +34,19 @@ "license": "MIT",

"concat-stream": "^1.4.6",
"decompress-tar": "^2.0.1",
"decompress-tarbz2": "^2.0.1",
"decompress-targz": "^2.0.1",
"decompress-unzip": "^2.0.0",
"download-status": "^2.0.1",
"each-async": "^1.0.0",
"get-stdin": "^3.0.0",
"get-stdin": "^4.0.1",
"got": "^2.3.2",
"gulp-decompress": "^1.0.2",
"gulp-rename": "^1.2.0",
"meow": "^2.0.0",
"rc": "^0.5.1",
"request": "^2.34.0",
"stream-combiner": "^0.2.1",
"meow": "^3.0.0",
"stream-combiner2": "^1.0.2",
"through2": "^0.6.1",
"url-regex": "^2.0.2",
"vinyl": "^0.4.3",
"vinyl-fs": "^0.3.7",
"ware": "^1.0.1"
"vinyl-fs": "^0.3.7"
},
"devDependencies": {
"archive-type": "^1.0.2",
"ava": "^0.0.4",
"gulp-tar": "^1.1.0",
"nock": "^0.52.4",
"nock": "^0.57.0",
"rimraf": "^2.2.8"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc