diff --git a/types/download/download-tests.ts b/types/download/download-tests.ts new file mode 100644 index 0000000000..7a498ef0dd --- /dev/null +++ b/types/download/download-tests.ts @@ -0,0 +1,30 @@ +import * as fs from 'fs'; +import download = require('download'); + +download('http://unicorn.com/foo.jpg', 'dist').then(() => { + console.log('done!'); +}); + +download('http://unicorn.com/foo.jpg').then(data => { + fs.writeFileSync('dist/foo.jpg', data); +}); + +download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg')); + +download('unicorn.com/foo.jpg', 'dest', { + body: '', + decompress: true, + encoding: 'utf8', + extract: true, + filename: 'filename', + followRedirect: true, + proxy: '', + query: '', + retries: (retry: number, error: any) => 4, + timeout: { + connect: 20, + request: 20, + socket: 20 + }, + useElectronNet: true +}); diff --git a/types/download/index.d.ts b/types/download/index.d.ts new file mode 100644 index 0000000000..f3af9778bf --- /dev/null +++ b/types/download/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for download 6.2 +// Project: https://github.com/kevva/download +// Definitions by: Nico Jansen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// + +interface TimeoutOptions { + connect?: number; + socket?: number; + request?: number; +} +type RetryFunction = (retry: number, error: any) => number; + +interface DownloadOptions { + body?: string | Buffer | NodeJS.ReadableStream; + encoding?: string | null; + query?: string | object; + timeout?: number | TimeoutOptions; + retries?: number | RetryFunction; + followRedirect?: boolean; + decompress?: boolean; + useElectronNet?: boolean; + /** + * If set to true, try extracting the file using decompress. + */ + extract?: boolean; + /** + * Name of the saved file. + */ + filename?: string; + /** + * Proxy endpoint + */ + proxy?: string; +} + +declare function download(url: string, destination?: string, options?: DownloadOptions): Promise & NodeJS.WritableStream & NodeJS.ReadableStream; + +export = download; diff --git a/types/download/tsconfig.json b/types/download/tsconfig.json new file mode 100644 index 0000000000..634ae5ab32 --- /dev/null +++ b/types/download/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "download-tests.ts" + ] +} diff --git a/types/download/tslint.json b/types/download/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/download/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }