UNPKG

ipull

Version:

The only file downloader you'll ever need. For node.js and the browser, CLI and library for fast and reliable file downloads.

55 lines (54 loc) 2.48 kB
import { DownloadFile, SaveProgressInfo } from "../types.js"; import DownloadEngineFile, { DownloadEngineFileOptions } from "../download-file/download-engine-file.js"; import BaseDownloadEngineFetchStream, { BaseDownloadEngineFetchStreamOptions } from "../streams/download-engine-fetch-stream/base-download-engine-fetch-stream.js"; import { EventEmitter } from "eventemitter3"; import ProgressStatisticsBuilder from "../../transfer-visualize/progress-statistics-builder.js"; import retry from "async-retry"; import { AvailablePrograms } from "../download-file/download-programs/switch-program.js"; import { FormattedStatus } from "../../transfer-visualize/format-transfer-status.js"; export type InputURLOptions = { partURLs: string[]; } | { url: string; }; export type CreateDownloadFileOptions = { reuseRedirectURL?: boolean; }; export type BaseDownloadEngineOptions = CreateDownloadFileOptions & InputURLOptions & BaseDownloadEngineFetchStreamOptions & { chunkSize?: number; parallelStreams?: number; retry?: retry.Options; comment?: string; programType?: AvailablePrograms; autoIncreaseParallelStreams?: boolean; }; export type BaseDownloadEngineEvents = { start: () => void; paused: () => void; resumed: () => void; progress: (progress: FormattedStatus) => void; save: (progress: SaveProgressInfo) => void; finished: () => void; closed: () => void; [key: string]: any; }; export default class BaseDownloadEngine extends EventEmitter<BaseDownloadEngineEvents> { readonly options: DownloadEngineFileOptions; protected readonly _engine: DownloadEngineFile; protected _progressStatisticsBuilder: ProgressStatisticsBuilder; protected _latestStatus?: FormattedStatus; protected constructor(engine: DownloadEngineFile, options: DownloadEngineFileOptions); get file(): DownloadFile; get downloadSize(): number; get fileName(): string; get status(): FormattedStatus; get downloadStatues(): FormattedStatus[]; protected _initEvents(): void; download(): Promise<void>; pause(): Promise<void>; resume(): void; close(): Promise<void>; protected static _createDownloadFile(parts: string[], fetchStream: BaseDownloadEngineFetchStream, { reuseRedirectURL }?: CreateDownloadFileOptions): Promise<DownloadFile>; protected static _validateURL(options: InputURLOptions): void; protected static _validateOptions(options: BaseDownloadEngineOptions): void; }