UNPKG

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