download-to-file
Advanced tools
Comparing version
@@ -22,5 +22,7 @@ 'use strict' | ||
var file = fs.createWriteStream(filepath) | ||
pump(res, file, cb) | ||
pump(res, file, function (err) { | ||
cb(err, filepath) | ||
}) | ||
}) | ||
}).on('error', cb) | ||
} |
{ | ||
"name": "download-to-file", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Download a file to disk programmatically", | ||
@@ -8,6 +8,6 @@ "main": "index.js", | ||
"mkdirp": "^0.5.1", | ||
"pump": "^1.0.2" | ||
"pump": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"standard": "^8.6.0", | ||
"standard": "^10.0.3", | ||
"tape": "^4.6.3" | ||
@@ -36,5 +36,5 @@ }, | ||
"coordinates": [ | ||
53.561964585443945, | ||
9.98561523076171 | ||
48.866051, | ||
2.3565218 | ||
] | ||
} |
@@ -20,5 +20,5 @@ # 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, filepath) { | ||
if (err) throw err | ||
console.log('Download finished') | ||
console.log('Download finished:', filepath) | ||
}) | ||
@@ -33,3 +33,4 @@ ``` | ||
specified by `filepath`. When done, the `callback` will be called with | ||
an optional error object as the first argument. | ||
an optional error object as the first argument and the `filepath` as the | ||
second argument. | ||
@@ -36,0 +37,0 @@ If the server does not return a 200 HTTP status code, the callback will |
@@ -20,6 +20,7 @@ 'use strict' | ||
var file = path.join(DIR, String(Date.now())) | ||
download(url, file, function (err) { | ||
download(url, file, function (err, filepath) { | ||
t.error(err) | ||
t.ok(fs.existsSync(file)) | ||
t.ok(fs.readFileSync(file), 'Hello World') | ||
t.equal(file, filepath) | ||
server.close() | ||
@@ -26,0 +27,0 @@ t.end() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4998
2.88%67
4.69%41
2.5%6
-14.29%+ Added
- Removed
Updated