download-to-file
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -10,3 +10,3 @@ 'use strict' | ||
module.exports = function (url, dir, name, cb) { | ||
module.exports = function (url, filepath, cb) { | ||
var transport = url.indexOf('https://') === 0 ? https : http | ||
@@ -20,5 +20,5 @@ return transport.get(url, function (res) { | ||
} | ||
mkdirp(dir, function (err) { | ||
mkdirp(path.dirname(filepath), function (err) { | ||
if (err) return cb(err) | ||
var file = fs.createWriteStream(path.join(dir, name)) | ||
var file = fs.createWriteStream(filepath) | ||
pump(res, file, cb) | ||
@@ -25,0 +25,0 @@ }) |
{ | ||
"name": "download-to-file", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Download a file to disk programmatically", | ||
@@ -35,5 +35,5 @@ "main": "index.js", | ||
"coordinates": [ | ||
53.56204936448514, | ||
9.985748261450226 | ||
53.561964585443945, | ||
9.98561523076171 | ||
] | ||
} |
@@ -20,3 +20,3 @@ # download-to-file | ||
console.log('Downloading to /tmp/example.html') | ||
download('http://example.com/', '/tmp', 'example.html', function (err) { | ||
download('http://example.com/', '/tmp/example.html', function (err) { | ||
if (err) throw err | ||
@@ -29,7 +29,7 @@ console.log('Download finished') | ||
### `download(url, directory, filename, callback)` | ||
### `download(url, filepath, callback)` | ||
Will download the content of the given `url` and store it in `filename` | ||
inside the `directory`. When done, the `callback` will be called with an | ||
optional error object as the first argument. | ||
Will download the content of the given `url` and store it in a file | ||
specified by `filepath`. When done, the `callback` will be called with | ||
an optional error object as the first argument. | ||
@@ -36,0 +36,0 @@ If the server does not return a 200 HTTP status code, the callback will |
10
test.js
@@ -19,5 +19,4 @@ 'use strict' | ||
var url = 'http://localhost:' + server.address().port | ||
var filename = Date.now() + '.tmp' | ||
var file = path.join(DIR, filename) | ||
download(url, DIR, filename, function (err) { | ||
var file = path.join(DIR, String(Date.now())) | ||
download(url, file, function (err) { | ||
t.error(err) | ||
@@ -40,5 +39,4 @@ t.ok(fs.existsSync(file)) | ||
var url = 'http://localhost:' + server.address().port | ||
var filename = Date.now() + '.tmp' | ||
var file = path.join(DIR, filename) | ||
download(url, DIR, filename, function (err) { | ||
var file = path.join(DIR, String(Date.now())) | ||
download(url, file, function (err) { | ||
t.equal(err.code, 500) | ||
@@ -45,0 +43,0 @@ t.equal(err.message, 'Unexpected HTTP status code: 500') |
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
4858
64