mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
feat(download): Add download types
This commit is contained in:
30
types/download/download-tests.ts
Normal file
30
types/download/download-tests.ts
Normal file
@@ -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
|
||||
});
|
||||
41
types/download/index.d.ts
vendored
Normal file
41
types/download/index.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// Type definitions for download 6.2
|
||||
// Project: https://github.com/kevva/download
|
||||
// Definitions by: Nico Jansen <https://github.com/nicojs>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
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<Buffer> & NodeJS.WritableStream & NodeJS.ReadableStream;
|
||||
|
||||
export = download;
|
||||
23
types/download/tsconfig.json
Normal file
23
types/download/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/download/tslint.json
Normal file
1
types/download/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user