@xingrz/download2
v9.0.0-alpha.4
Published
Download and extract files
Downloads
28
Maintainers
Readme
@xingrz/download2
Download and extract files.
Install
npm install --save @xingrz/download2
Usage
import { writeFileSync, createWriteStream } from 'fs';
import download from '@xingrz/download2';
(async () => {
await download('http://unicorn.com/foo.jpg', 'dist');
writeFileSync('dist/foo.jpg', await download('http://unicorn.com/foo.jpg'));
download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
await Promise.all([
'unicorn.com/foo.jpg',
'cats.com/dancing.gif'
].map(url => download(url, 'dist')));
})();
Proxies
To work with proxies, read the got documentation
.
API
download(url[, destination][, options])
Returns both a Promise<Buffer>
and a Duplex stream with additional events.
If extract: true
is set, returns Promise<File[]>
instead of Promise<Buffer>
.
url
Type: string
URL to download.
destination
Type: string
(optional)
Path to directory where your file will be written.
options
Type: Object
Same options as got
and @xingrz/decompress
in addition to the ones below.
extract
Type: boolean
If set to true
, try extracting the file using @xingrz/decompress
.
filename
Type: string
Name of the saved file. Will be ignored if extract
is set to true
.
License
MIT © Kevin Mårtensson, XiNGRZ