Socket
Socket
Sign inDemoInstall

download

Package Overview
Dependencies
241
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.1 to 4.1.0

24

cli.js

@@ -11,12 +11,12 @@ #!/usr/bin/env node

'Usage',
' download <url>',
' download <url> > <file>',
' download --out <directory> <url>',
' cat <file> | download --out <directory>',
' $ download <url>',
' $ download <url> > <file>',
' $ download --out <directory> <url>',
' $ cat <file> | download --out <directory>',
'',
'Example',
' download http://foo.com/file.zip',
' download http://foo.com/cat.png > dog.png',
' download --extract --strip 1 --out dest http://foo.com/file.zip',
' cat urls.txt | download --out dest',
' $ download http://foo.com/file.zip',
' $ download http://foo.com/cat.png > dog.png',
' $ download --extract --strip 1 --out dest http://foo.com/file.zip',
' $ cat urls.txt | download --out dest',
'',

@@ -78,6 +78,6 @@ 'Options',

'Example',
' download http://foo.com/file.zip',
' download http://foo.com/cat.png > dog.png',
' download --extract --strip 1 --out dest http://foo.com/file.zip',
' cat urls.txt | download --out dest'
' $ download http://foo.com/file.zip',
' $ download http://foo.com/cat.png > dog.png',
' $ download --extract --strip 1 --out dest http://foo.com/file.zip',
' $ cat urls.txt | download --out dest'
].join('\n'));

@@ -84,0 +84,0 @@

@@ -8,8 +8,11 @@ 'use strict';

var File = require('vinyl');
var filenamify = require('filenamify');
var got = require('got');
var isUrl = require('is-url');
var objectAssign = require('object-assign');
var path = require('path');
var rename = require('gulp-rename');
var through = require('through2');
var urlRegex = require('url-regex');
var vfs = require('vinyl-fs');
var Ware = require('ware');

@@ -28,5 +31,8 @@ /**

this.opts = opts || {};
this.opts = objectAssign({encoding: null}, opts);
this.ware = new Ware();
}
module.exports = Download;
/**

@@ -87,2 +93,14 @@ * Get or set URL to download

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

@@ -99,3 +117,3 @@ *

eachAsync(this.get(), function (get, i, done) {
if (!urlRegex().test(get.url)) {
if (!isUrl(get.url)) {
done(new Error('Specify a valid URL'));

@@ -105,20 +123,19 @@ return;

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

@@ -143,9 +160,6 @@ if (err) {

Download.prototype.createFile = function (url, data) {
var obj = new File({
return objectAssign(new File({
contents: data,
path: path.basename(url)
});
obj.url = url;
return obj;
path: filenamify(path.basename(url))
}), {url: url});
};

@@ -181,7 +195,1 @@

};
/**
* Module exports
*/
module.exports = Download;
{
"name": "download",
"version": "4.0.1",
"version": "4.1.0",
"description": "Download and extract files effortlessly",

@@ -35,2 +35,3 @@ "license": "MIT",

"each-async": "^1.0.0",
"filenamify": "^1.0.1",
"get-stdin": "^4.0.1",

@@ -40,14 +41,16 @@ "got": "^2.3.2",

"gulp-rename": "^1.2.0",
"is-url": "^1.2.0",
"meow": "^3.0.0",
"object-assign": "^2.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"
"vinyl-fs": "^1.0.0",
"ware": "^1.2.0"
},
"devDependencies": {
"ava": "^0.0.4",
"nock": "^0.57.0",
"nock": "^1.2.1",
"rimraf": "^2.2.8"
}
}

@@ -5,8 +5,10 @@ # download [![Build Status](http://img.shields.io/travis/kevva/download.svg?style=flat)](https://travis-ci.org/kevva/download)

## Install
```sh
```
$ npm install --save download
```
## Usage

@@ -20,25 +22,29 @@

var download = new Download({extract: true, strip: 1, mode: '755'})
new Download({mode: '755'})
.get('http://example.com/foo.zip')
.get('http://example.com/cat.jpg')
.dest('dest');
.run(function (err, files) {
console.log(files);
//=> [{path: 'foo.zip', url: 'http://example.com/foo.zip', contents: <Buffer 50 4b 03>, ...}, ...]
});
```
download.run(function (err, files) {
if (err) {
throw err;
}
console.log('File downloaded successfully!');
});
```
## API
### new Download(opts)
### new Download(options)
Creates a new `Download` instance.
#### opts.extract
#### options
Type: `Boolean`
Type: `object`
Options for [`got`](https://github.com/sindresorhus/got) or the underlying [`http`](https://nodejs.org/api/http.html#http_http_request_options_callback)/[`https`](https://nodejs.org/api/https.html#https_https_request_options_callback) request can be specified,
as well as options specific to the `download` module as described below.
##### options.extract
Type: `boolean`
Default: `false`

@@ -48,14 +54,14 @@

#### opts.mode
##### options.mode
Type: `String`
Type: `string`
Set mode on the downloaded file, i.e `{mode: '755'}`.
#### opts.strip
##### options.strip
Type: `Number`
Type: `number`
Default: `0`
Equivalent to `--strip-components` for tar.
Remove leading directory components from extracted files.

@@ -66,3 +72,3 @@ ### .get(url, [dest])

Type: `String`
Type: `string`

@@ -73,3 +79,3 @@ Add a URL to download.

Type: `String`
Type: `string`

@@ -83,3 +89,3 @@ Set an optional destination folder that will take precedence over the one set in

Type: `String`
Type: `string`

@@ -92,43 +98,55 @@ Set the destination folder to where your files will be downloaded.

Type: `Function|String`
Type: `function` or `string`
Rename your files using [gulp-rename](https://github.com/hparra/gulp-rename).
### .run(cb)
### .use(plugin)
#### cb(err, files)
#### plugin
Type: `Function`
Type: `function`
The callback will return an array of vinyl files.
Add a plugin to the middleware stack.
### .run(callback)
#### callback(err, files)
Type: `function`
##### files
Contains an array of vinyl files.
## CLI
```bash
```
$ npm install --global download
```
```sh
```
$ download --help
Usage
download <url>
download <url> > <file>
download --out <directory> <url>
cat <file> | download --out <directory>
Usage
$ download <url>
$ download <url> > <file>
$ download --out <directory> <url>
$ cat <file> | download --out <directory>
Example
download http://foo.com/file.zip
download http://foo.com/cat.png > dog.png
download --extract --strip 1 --out dest http://foo.com/file.zip
cat urls.txt | download --out dest
Example
$ download http://foo.com/file.zip
$ download http://foo.com/cat.png > dog.png
$ download --extract --strip 1 --out dest http://foo.com/file.zip
$ cat urls.txt | download --out dest
Options
-e, --extract Try decompressing the file
-o, --out Where to place the downloaded files
-s, --strip <number> Strip leading paths from file names on extraction
Options
-e, --extract Try decompressing the file
-o, --out Where to place the downloaded files
-s, --strip <number> Strip leading paths from file names on extraction
```
## License
MIT © [Kevin Mårtensson](http://kevinmartensson.com)
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