UNPKG

node-downloader-manager

Version:

node-downloader-manager is a simple yet powerful package manager-like download manager built with NodeJs. It allows you to download files sequentially or with a queue-based approach, handling retries and concurrency limits efficiently.

47 lines (46 loc) 1.91 kB
import { EventEmitter } from "node:events"; import type { DownloadManagerOptions, EmitDataType } from "../types"; import { EmitEventType } from "../config/const"; declare class DownloadManager extends EventEmitter { private readonly options; private readonly downloadQueue; private readonly downloadThread; private readonly method; private readonly concurrencyLimit; private readonly downloadFolder; private readonly getFileName?; private readonly onAfterDownload?; private readonly onBeforeDownload?; private readonly log; private readonly overWriteFile; private readonly stream; private readonly requestOptions; private readonly activeDownloads; private readonly currentUrl; private readonly currentDownloadableUrl; private readonly timeout; constructor(options?: DownloadManagerOptions); private logger; on(event: EmitEventType, callback: (data?: EmitDataType) => void): this; emit(event: EmitEventType, data?: EmitDataType): boolean; pauseDownload(url?: string): void; resumeDownload(url?: string): Promise<void>; pauseAll(): void; resumeAll(): void; cancelDownload(url?: string): Promise<void>; cancelAll(): Promise<void>; private normalizeHeaders; private streamDownload; private downloadFile; private isValidUrl; private invalidUrlEmit; enqueueDownloadTask(url: string, fileName: string, downloadedBytes?: number, priority?: number): void; addThreadDownloadTask(url: string, fileName: string): void; terminateThreads(): void; private createFileName; simpleDownload(urls: string | string[], fileName?: string): Promise<void>; queueDownload(urls: string | string[]): Promise<void>; threadDownload(urls: string | string[]): Promise<void>; download(urls: string | string[], fileName?: string): Promise<void>; } export default DownloadManager;