get-down
Download and optionally extract files.
This draws heavily from Bower's download and extract utilities. Those utilities are copyright Twitter and carry the MIT license.
Example use
Download a file and save it to the working directory with the same name:
var download = require('get-down');
download('http://example.com/file.txt');
Same as above, but saving to a different directory:
var download = require('get-down');
download('http://example.com/file.txt', {dest: 'different/directory'});
In addition to providing a dest
directory, you can provide a new file name:
var download = require('get-down');
download('http://example.com/file.txt', {dest: 'different/name.txt'});
The extract
option can be used to extract tar
, tgz
, gz
, or zip
files:
var download = require('get-down');
download('http://example.com/file.zip', {dest: 'some/directory', extract: true});
As you might expect, download
is all async. You get an event emitter in return:
var download = require('get-down');
download('http://example.com/file.txt').on('end', function(dest) {
console.log('downloaded', dest);
});
API Docs
download(url, [options])
Available options:
- dest -
string
The destination for saving downloaded resources. - extract -
boolean
Extract the downloaded archive.
The download
method returns an event emitter with the following events:
- progress - Emitted periodically during the download.
- error - Emitted on any error.
- end - Emitted when the download is complete. Listeners will be called with the path to the downloaded file (or directory in the case of an extracted archive).