iterparse
Version:
Delightful data parsing
48 lines • 1.65 kB
TypeScript
import { Headers, RequestInit } from 'node-fetch';
import { DownloadProgress } from './helpers';
import { IX } from './types';
export declare type ResourceIDHookFunction = ((url: string, headers: Headers) => string);
export interface DownloadOptions extends RequestInit {
url: string;
/**
* Folder where file will be downloaded
*/
downloadFolder: string;
/**
* Hook for tracking download progress
* @example
* (progress) => console.log(progress.toString())
*/
progress?: (progress: DownloadProgress) => void;
/**
* How often notify about progress?
* @defaultValue `3000ms`
*/
progressFrequency?: number;
/**
* Resource ID generation logic.
* Basically we can take some data from response and convert to resource ID
* Examples
* * etag - from response headers
* * last-modified - from response headers
*
* If file with same generated resource ID is found file will not be downloaded.
*/
resourceId?: string | ResourceIDHookFunction | false;
}
/**
* Function will download any resource from interned and cache it in local file system.
*
* @param url URL to file
* @include ./DownloadOptions.md
* @example
* import { download } from 'iterparse'
* download({ url: "url/to/resource.csv", downloadFolder: "/tmp", progress: (q) => console.log(q.toString()) })
* .flatMap((filePath)=> csvRead({ filePath }))
* .map((q)=> console.log(q))
* .count()
*
* @category Utility
*/
export declare function download(options: DownloadOptions): IX<string>;
//# sourceMappingURL=download.d.ts.map