Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevva/download
Download and extract files
https://github.com/kevva/download
async decompress download extract http nodejs promise stream
Last synced: 25 days 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 11 years ago)
- Default Branch: master
- Last Pushed: 2023-10-08T19:06:13.000Z (about 1 year ago)
- Last Synced: 2024-10-09T16:11:31.065Z (30 days ago)
- Topics: async, decompress, download, extract, http, nodejs, promise, stream
- Language: JavaScript
- Homepage:
- Size: 244 KB
- Stars: 1,282
- Watchers: 20
- Forks: 199
- Open Issues: 65
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-nodejs-cn - download - 使下载和提取文件变得轻松 (包 / HTTP)
- awesome-nodejs - download - Download and extract files effortlessly. ![](https://img.shields.io/github/stars/kevva/download.svg?style=social&label=Star) (Repository / HTTP)
- awesome-nodejs - download - 轻松下载和提取文件。 ![](https://img.shields.io/github/stars/kevva/download.svg?style=social&label=Star) (GIT 仓库 / HTTP)
- awesome-github-star - download
- awesome-npm - download - 文件下载库 (1. 后端开发 / 1.1 HTTP)
- awesome-nodejs - download - Download and extract files - ★ 768 (HTTP)
- awesome-node - download - Download and extract files effortlessly. (Packages / HTTP)
- awesome-nodejs - download - 下载并解压文件 (Uncategorized / Uncategorized)
- awesome-nodejs-cn - download - 轻松下载和提取文件. (目录 / HTTP)
README
# download [![Build Status](https://travis-ci.org/kevva/download.svg?branch=master)](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.