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.

57 lines (56 loc) 2.76 kB
import { EventEmitter } from "eventemitter3"; import { FormattedStatus } from "../../transfer-visualize/format-transfer-status.js"; import ProgressStatisticsBuilder from "../../transfer-visualize/progress-statistics-builder.js"; import BaseDownloadEngine, { BaseDownloadEngineEvents } from "./base-download-engine.js"; import { DownloadEngineRemote } from "./DownloadEngineRemote.js"; export type DownloadEngineMultiAllowedEngines = BaseDownloadEngine | DownloadEngineRemote | DownloadEngineMultiDownload<any>; type DownloadEngineMultiDownloadEvents<Engine = DownloadEngineMultiAllowedEngines> = BaseDownloadEngineEvents & { childDownloadStarted: (engine: Engine) => void; childDownloadClosed: (engine: Engine) => void; downloadAdded: (engine: Engine) => void; }; export type DownloadEngineMultiDownloadOptions = { parallelDownloads?: number; /** * Unpack inner downloads statues to the main download statues, * useful for showing CLI progress in separate downloads or tracking download progress separately */ unpackInnerMultiDownloadsStatues?: boolean; /** * Finalize download (change .ipull file to original extension) after all downloads are settled */ finalizeDownloadAfterAllSettled?: boolean; downloadName?: string; downloadComment?: string; }; export default class DownloadEngineMultiDownload<Engine extends DownloadEngineMultiAllowedEngines = DownloadEngineMultiAllowedEngines> extends EventEmitter<DownloadEngineMultiDownloadEvents> { readonly downloads: Engine[]; protected _options: DownloadEngineMultiDownloadOptions; protected _aborted: boolean; protected _activeEngines: Set<Engine>; protected _progressStatisticsBuilder: ProgressStatisticsBuilder; protected _downloadStatues: FormattedStatus[] | FormattedStatus[][]; protected _closeFiles: (() => Promise<void>)[]; protected _lastStatus: FormattedStatus; protected _loadingDownloads: number; protected _reloadDownloadParallelisms?: () => void; protected _engineWaitPromises: Set<Promise<Engine>>; get activeDownloads(): Engine[]; get parallelDownloads(): number | undefined; get loadingDownloads(): number; set parallelDownloads(value: number | undefined); get downloadStatues(): FormattedStatus[]; get status(): FormattedStatus; get downloadSize(): number; protected _init(): void; private _addEngine; _addDownloadNoStatisticUpdate(engine: Engine | Promise<Engine>): Promise<Engine>; addDownload(...engines: (Engine | Promise<Engine>)[]): Promise<void>; download(): Promise<void>; private _changeEngineFinishDownload; private _finishEnginesDownload; pause(): void; resume(): void; close(): Promise<void>; } export {};