# @xingrz/download2

> Download and extract files

Latest version **9.0.0-alpha.4** (published 2021-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xingrz/download2
pnpm add @xingrz/download2
yarn add @xingrz/download2
bun add @xingrz/download2
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.0.0-alpha.4 |
| Published | 2021-11-13 |
| First published | 2021-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 9 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kevin Mårtensson |
| Maintainers | xingrz |
| Keywords | download, extract, http, request, url |

## Links

- npm: https://www.npmjs.com/package/@xingrz/download2
- Repository: https://github.com/xingrz/download
- Homepage: https://github.com/xingrz/download#readme
- Issues: https://github.com/xingrz/download/issues
- npm.io page: https://npm.io/package/@xingrz/download2

## Dependencies (9)

- [got](https://npm.io/package/got.md) ^11.8.2
- [p-event](https://npm.io/package/p-event.md) ^4.2.0
- [ext-name](https://npm.io/package/ext-name.md) ^5.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [file-type](https://npm.io/package/file-type.md) ^16.5.3
- [filenamify](https://npm.io/package/filenamify.md) ^3.0.0
- [get-stream](https://npm.io/package/get-stream.md) ^6.0.1
- [@xingrz/decompress](https://npm.io/package/@xingrz/decompress.md) ^5.2.0-alpha.1
- [content-disposition](https://npm.io/package/content-disposition.md) ^0.5.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 9.0.0-alpha.4 (latest) — 2021-11-13
- 9.0.0-alpha.3 — 2021-11-12
- 9.0.0-alpha.2 — 2021-11-03
- 9.0.0-alpha.1 — 2021-11-03
- 9.0.0-alpha.0 — 2021-11-03

## README

@xingrz/download2 [![test](https://github.com/xingrz/download/actions/workflows/test.yml/badge.svg)](https://github.com/xingrz/download/actions/workflows/test.yml)
==========

[![][npm-version]][npm-url] [![][npm-downloads]][npm-url] [![license][license-img]][license-url] [![issues][issues-img]][issues-url] [![stars][stars-img]][stars-url] [![commits][commits-img]][commits-url]

Download and extract files.

## Install

```sh
npm install --save @xingrz/download2
```

## Usage

```ts
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`](https://github.com/sindresorhus/got#proxies).

## API

### `download(url[, destination][, options])`

Returns both a `Promise<Buffer>` and a [Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with [additional events](https://github.com/sindresorhus/got#streams-1).

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`](https://github.com/sindresorhus/got#options) and [`@xingrz/decompress`](https://github.com/xingrz/decompress#options) in addition to the ones below.

##### `extract`

Type: `boolean`

If set to `true`, try extracting the file using [`@xingrz/decompress`](https://github.com/xingrz/decompress).

##### `filename`

Type: `string`

Name of the saved file. Will be ignored if `extract` is set to `true`.

## License

MIT © [Kevin Mårtensson](https://github.com/kevva), [XiNGRZ](https://github.com/xingrz)

[npm-version]: https://img.shields.io/npm/v/@xingrz/download2.svg?style=flat-square
[npm-downloads]: https://img.shields.io/npm/dm/@xingrz/download2.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@xingrz/download2
[license-img]: https://img.shields.io/github/license/xingrz/download?style=flat-square
[license-url]: LICENSE
[issues-img]: https://img.shields.io/github/issues/xingrz/download?style=flat-square
[issues-url]: https://github.com/xingrz/download/issues
[stars-img]: https://img.shields.io/github/stars/xingrz/download?style=flat-square
[stars-url]: https://github.com/xingrz/download/stargazers
[commits-img]: https://img.shields.io/github/last-commit/xingrz/download?style=flat-square
[commits-url]: https://github.com/xingrz/download/commits/master

---
_Source: https://npm.io/package/@xingrz/download2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
