UNPKG

@guoyunhe/downloader

Version:

Download large files with minimum RAM usage. Support tar.gz and zip extraction.

43 lines (42 loc) 1.23 kB
export interface DownloadProgress { /** Downloaded bytes so far. */ downloadedBytes: number; /** Total bytes from `content-length` header. `null` if unknown. */ totalBytes: number | null; /** Download percentage in [0, 100]. `null` if total size is unknown. */ percentage: number | null; } export interface DownloadOptions { /** * Maximum redirect times. * * @default 5 */ maxRedirects?: number; /** * Extract *.tar.gz archives * * @default false */ extract?: boolean; /** * Strip given number of leading components from file names before extraction. * * For example, if archive `archive.tar' contained `some/file/name', then `strip: 2` would extract * this file to file `name`. * * @default 0 */ strip?: number; /** * Receive streaming progress updates during download. */ onProgress?: (progress: DownloadProgress) => void; } export declare function download( /** File download URL. Must be public and support GET method. */ url: string, /** Output file (not extract) or folder (extract) path. */ dist: string, /** Extra download options. */ options?: DownloadOptions): Promise<void>;