1 | /// <reference types="node" />
|
2 | import { DecompressOptions } from "decompress";
|
3 | import { GotEmitter, GotOptions } from "got";
|
4 | import { Duplex } from "stream";
|
5 |
|
6 | declare namespace download {
|
7 | interface DownloadOptions extends DecompressOptions, GotOptions<string | null> {
|
8 | /**
|
9 | * If set to `true`, try extracting the file using
|
10 | * [`decompress`](https://github.com/kevva/decompress).
|
11 | *
|
12 | * @default false
|
13 | */
|
14 | extract?: boolean | undefined;
|
15 |
|
16 | /**
|
17 | * Name of the saved file.
|
18 | */
|
19 | filename?: string | undefined;
|
20 | }
|
21 | }
|
22 |
|
23 | /**
|
24 | * Download and extract files.
|
25 | *
|
26 | * @param url URL to download.
|
27 | * @param destination Path to where your file will be written.
|
28 | * @param options Same options as [`got`](https://github.com/sindresorhus/got#options)
|
29 | * and [`decompress`](https://github.com/kevva/decompress#options) in addition to the
|
30 | * ones from this package.
|
31 | *
|
32 | * @example
|
33 | * import fs from 'fs';
|
34 | * import download = require('download');
|
35 | *
|
36 | * (async () => {
|
37 | * await download('http://unicorn.com/foo.jpg', 'dist');
|
38 | *
|
39 | * fs.writeFileSync('dist/foo.jpg', await download('http://unicorn.com/foo.jpg'));
|
40 | *
|
41 | * download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
|
42 | *
|
43 | * await Promise.all([
|
44 | * 'unicorn.com/foo.jpg',
|
45 | * 'cats.com/dancing.gif'
|
46 | * ].map(url => download(url, 'dist')));
|
47 | * })();
|
48 | */
|
49 | declare function download(
|
50 | url: string,
|
51 | destination?: string,
|
52 | options?: download.DownloadOptions,
|
53 | ): Promise<Buffer> & GotEmitter & Duplex;
|
54 | declare function download(url: string, options?: download.DownloadOptions): Promise<Buffer> & GotEmitter & Duplex;
|
55 |
|
56 | export = download;
|