
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
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.
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'});
// the provided directory must already exist
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 provided file must not already exist
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});
// the dest directory must already exist
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);
});
download(url, [options])
string
URL for the resource you want to download. E.g. 'http://example.com/file.txt'
or 'https://example.com/archive.zip'
.Object
An optional object with properties to configure the download operation. See the available options below.Download a resource. Returns an EventEmitter
that emits the events described below.
string
process.cwd()
The destination directory or file path for saving downloaded resources. If dest
is a directory, it must already exist. If dest
is a path to a file, the parent directory must already exist (existing files will not be overwritten). If the extract
option is false
and you provide a directory here, the filename will be derived from the provided url
(e.g. a url
of 'http://example.com/some/file.txt'
and a dest
of 'local/path'
will result in 'local/path/file.txt'
). Finally, if the extract
option is true
, you must provide the path to an existing directory.
boolean
false
Extract the downloaded archive. If the url
points to a .zip, .tar, .tgz, or .gz file, you can optionally extract/defalate it after download. If not obvious from the file extension, the archive type will be determined from the content type header of the response.
progress
eventEmitted periodically during the download. Listeners will receive a state object representing one of two types of progress. As more data is received, the state object will have the following properties:
number
The cumulative number of bytes received.number|null
If the response headers provided it, this will be the total content size in bytes. If not provided, it will be null
.number|null
As a convenience, if total
is available, this will be the percentage of the total file size received (otherwise it will be null
).If the download fails due to network issues, it will be retried (up to 5 times). In the event of a retry, progress listeners will receive a state object with the following properties:
boolean
This will always be true
in the event of a retry.number
The number of milliseconds before the download is attempted again.Error
An error representing the failure.A progress listener might handle both types of progress with code like this:
download('http://example.com/big-file.txt').on('progress', function(state) {
if (state.retry) {
var delay = Math.round(state.timeout / 1000) + 's';
console.log('Download failed, retrying again in ' + delay);
} else {
var progress = Math.floor(state.received / 1024) + 'K';
if (state.percent) {
progress = state.percent + '% (' + progress + ')';
}
console.log('Received ' + progress);
}
});
error
eventEmitted in the event of an error during download or extraction. Listeners will receive an Error
object with a message describing what went wrong. Temporary files created during a download will be removed when your program completes.
end
eventEmitted in upon success. Listeners will be called with a (string
) path to the saved resource. If the extract
option is true
, this will be a path to the directory where the resource was extracted. Otherwise, it will be a path to the saved file.
Please report any issues you find. To contribute, fork and start out by running the tests.
npm install
npm test
You can run npm start
to have the linter and tests run continuously during development.
FAQs
Download and optionally extract files
We found that get-down demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.