https://github.com/kevva/download
  
  
    Download and extract files 
    https://github.com/kevva/download
  
async decompress download extract http nodejs promise stream
        Last synced: 6 months ago 
        JSON representation
    
Download and extract files
- Host: GitHub
 - URL: https://github.com/kevva/download
 - Owner: kevva
 - License: mit
 - Created: 2013-08-23T14:49:56.000Z (about 12 years ago)
 - Default Branch: master
 - Last Pushed: 2023-10-08T19:06:13.000Z (about 2 years ago)
 - Last Synced: 2025-03-12T08:11:10.896Z (8 months ago)
 - Topics: async, decompress, download, extract, http, nodejs, promise, stream
 - Language: JavaScript
 - Homepage:
 - Size: 244 KB
 - Stars: 1,293
 - Watchers: 19
 - Forks: 204
 - Open Issues: 66
 - 
            Metadata Files:
            
- Readme: readme.md
 - License: license
 
 
Awesome Lists containing this project
- awesome-nodejs - download - Download and extract files effortlessly.  (Repository / HTTP)
 - awesome-nodejs - download - 轻松下载和提取文件。  (GIT 仓库 / HTTP)
 - awesome-github-star - download
 - awesome-npm - download - 文件下载库 (1. 后端开发 / 1.1 HTTP)
 - awesome-node - download - Download and extract files effortlessly. (Packages / HTTP)
 - awesome-nodejs - download - Download and extract files - ★ 768 (HTTP)
 - awesome-nodejs-cn - download - 轻松下载和提取文件. (目录 / HTTP)
 - awesome-nodejs-cn - download - 使下载和提取文件变得轻松 (包 / HTTP)
 - awesome-nodejs - download - 下载并解压文件 (Uncategorized / Uncategorized)
 
README
          # download [](https://travis-ci.org/kevva/download)
> Download and extract files
*See [download-cli](https://github.com/kevva/download-cli) for the command-line version.*
## Install
```
$ npm install download
```
## Usage
```js
const fs = require('fs');
const download = require('download');
(async () => {
	await download('http://unicorn.com/foo.jpg', 'dist');
	fs.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`](https://github.com/sindresorhus/got#proxies).
## API
### download(url, destination?, options?)
Returns both a `Promise` and a [Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with [additional events](https://github.com/sindresorhus/got#streams-1).
#### url
Type: `string`
URL to download.
#### destination
Type: `string`
Path to where your file will be written.
#### options
Type: `Object`
Same options as [`got`](https://github.com/sindresorhus/got#options) and [`decompress`](https://github.com/kevva/decompress#options) in addition to the ones below.
##### extract
Type: `boolean`
Default: `false`
If set to `true`, try extracting the file using [`decompress`](https://github.com/kevva/decompress).
##### filename
Type: `string`
Name of the saved file.