Comparing version 0.1.7 to 0.1.8
@@ -9,3 +9,3 @@ 'use strict'; | ||
var request = require('request'); | ||
var stream = require('through2')(); | ||
var through = require('through2'); | ||
@@ -29,8 +29,11 @@ /** | ||
url = Array.isArray(url) ? url : [url]; | ||
opts = opts || {}; | ||
var stream = through(); | ||
var strip = opts.strip || '0'; | ||
var target; | ||
eachAsync(url, function (url, index, done) { | ||
opts = opts || {}; | ||
opts.url = url; | ||
opts.dest = path.join(dest, path.basename(url)); | ||
opts.strip = opts.strip || '0'; | ||
target = path.join(dest, path.basename(url)); | ||
@@ -55,2 +58,3 @@ var req = request.get(opts) | ||
stream.emit('error', status); | ||
return; | ||
} | ||
@@ -67,3 +71,7 @@ | ||
end = decompress.extract({ ext: ext, path: dest, strip: opts.strip }); | ||
end = decompress.extract({ | ||
ext: ext, | ||
path: dest, | ||
strip: strip | ||
}); | ||
} else { | ||
@@ -74,3 +82,3 @@ if (!fs.existsSync(dest)) { | ||
end = fs.createWriteStream(opts.dest); | ||
end = fs.createWriteStream(target); | ||
} | ||
@@ -82,9 +90,10 @@ | ||
if (!opts.extract && opts.mode) { | ||
fs.chmodSync(opts.dest, opts.mode); | ||
fs.chmodSync(target, opts.mode); | ||
} | ||
stream.emit('close'); | ||
done(); | ||
}); | ||
}); | ||
}, function () { | ||
stream.emit('close'); | ||
}); | ||
@@ -91,0 +100,0 @@ |
{ | ||
"name": "download", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Download and extract files effortlessly", | ||
@@ -28,15 +28,16 @@ "keywords": [ | ||
"dependencies": { | ||
"decompress": "~0.1.0", | ||
"decompress": "~0.1.5", | ||
"each-async": "~0.1.1", | ||
"mkdirp": "~0.3.5", | ||
"request": "~2.25.0", | ||
"through2": "~0.1.0" | ||
"nock": "~0.27.1", | ||
"request": "~2.31.0", | ||
"through2": "~0.4.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.12.0", | ||
"rimraf": "~2.2.2" | ||
"mocha": "~1.17.0", | ||
"rimraf": "~2.2.5" | ||
}, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=0.10.0" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # download [![Build Status](https://secure.travis-ci.org/kevva/download.png?branch=master)](http://travis-ci.org/kevva/download) | ||
If you're fetching an archive you can set `extract: true` in options and | ||
If you're fetching an archive you can set `extract: true` in options and | ||
it'll extract it for you. | ||
@@ -34,14 +34,40 @@ | ||
Download a file or an array of files to a given destination. Returns an EventEmitter | ||
with three possible events — `response`, `data` and `error`. | ||
that emits the following possible events: | ||
* `response` — Relayed when the underlying `http.ClientRequest` emits the same | ||
event. Listeners called with a `http.IncomingMessage` instance. | ||
* `data` — Relayed when the underlying `http.IncomingMessage` emits the same | ||
event. Listeners called with a `Buffer` instance. | ||
* `error` — Relayed when the underlying `http.ClientRequest` emits the same event | ||
or when the response status code is not in the 200s. Listeners called with an | ||
`Error` instance (in the first case) or the response status code. | ||
* `close` — Relayed when the underlying `stream.Duplex` emits the same event. | ||
## Options | ||
* `extract` — If set to `true`, try extracting the file using [decompress](https://github.com/kevva/decompress/) | ||
* `mode` — Set mode on the downloaded files | ||
* `strip` — Equivalent to `--strip-components` for tar | ||
You can define options accepted by the [request](https://github.com/mikeal/request/) module besides from the options below. | ||
You can also define options accepted by the [request](https://github.com/mikeal/request/) module. | ||
### extract | ||
Type: `Boolean` | ||
Default: `false` | ||
If set to `true`, try extracting the file using [decompress](https://github.com/kevva/decompress/). | ||
### mode | ||
Type: `String` | ||
Default: `undefined` | ||
Set mode on the downloaded files. | ||
### strip | ||
Type: `Number` | ||
Default: `0` | ||
Equivalent to `--strip-components` for tar. | ||
## License | ||
[MIT License](http://en.wikipedia.org/wiki/MIT_License) (c) [Kevin Mårtensson](http://kevinmartensson.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5421
80
72
6
+ Addednock@~0.27.1
+ Addedaws-sign2@0.5.0(transitive)
+ Addednock@0.27.3(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedpropagate@0.2.2(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrequest@2.31.0(transitive)
+ Addedthrough2@0.4.2(transitive)
+ Addedtough-cookie@0.9.15(transitive)
+ Addedxtend@2.1.2(transitive)
- Removedaws-sign@0.3.0(transitive)
- Removedcookie-jar@0.3.0(transitive)
- Removedforeach@2.0.6(transitive)
- Removedindexof@0.0.1(transitive)
- Removedis@0.2.7(transitive)
- Removedis-object@0.1.2(transitive)
- Removedobject-keys@0.2.0(transitive)
- Removedrequest@2.25.0(transitive)
- Removedthrough2@0.1.0(transitive)
- Removedxtend@2.0.6(transitive)
Updateddecompress@~0.1.5
Updatedrequest@~2.31.0
Updatedthrough2@~0.4.0