UNPKG

2.53 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/download`
3
4# Summary
5This package contains type definitions for download (https://github.com/kevva/download).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/download.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/download/index.d.ts)
10````ts
11/// <reference types="node" />
12import { DecompressOptions } from "decompress";
13import { GotEmitter, GotOptions } from "got";
14import { Duplex } from "stream";
15
16declare namespace download {
17 interface DownloadOptions extends DecompressOptions, GotOptions<string | null> {
18 /**
19 * If set to `true`, try extracting the file using
20 * [`decompress`](https://github.com/kevva/decompress).
21 *
22 * @default false
23 */
24 extract?: boolean | undefined;
25
26 /**
27 * Name of the saved file.
28 */
29 filename?: string | undefined;
30 }
31}
32
33/**
34 * Download and extract files.
35 *
36 * @param url URL to download.
37 * @param destination Path to where your file will be written.
38 * @param options Same options as [`got`](https://github.com/sindresorhus/got#options)
39 * and [`decompress`](https://github.com/kevva/decompress#options) in addition to the
40 * ones from this package.
41 *
42 * @example
43 * import fs from 'fs';
44 * import download = require('download');
45 *
46 * (async () => {
47 * await download('http://unicorn.com/foo.jpg', 'dist');
48 *
49 * fs.writeFileSync('dist/foo.jpg', await download('http://unicorn.com/foo.jpg'));
50 *
51 * download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
52 *
53 * await Promise.all([
54 * 'unicorn.com/foo.jpg',
55 * 'cats.com/dancing.gif'
56 * ].map(url => download(url, 'dist')));
57 * })();
58 */
59declare function download(
60 url: string,
61 destination?: string,
62 options?: download.DownloadOptions,
63): Promise<Buffer> & GotEmitter & Duplex;
64declare function download(url: string, options?: download.DownloadOptions): Promise<Buffer> & GotEmitter & Duplex;
65
66export = download;
67
68````
69
70### Additional Details
71 * Last updated: Mon, 06 Nov 2023 22:41:05 GMT
72 * Dependencies: [@types/decompress](https://npmjs.com/package/@types/decompress), [@types/got](https://npmjs.com/package/@types/got), [@types/node](https://npmjs.com/package/@types/node)
73
74# Credits
75These definitions were written by [Nico Jansen](https://github.com/nicojs), and [BendingBender](https://github.com/BendingBender).
76
\No newline at end of file