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.
41 lines • 1.7 kB
JavaScript
import DownloadEngineNodejs from "./download-engine/engine/download-engine-nodejs.js";
import BaseDownloadEngine from "./download-engine/engine/base-download-engine.js";
import DownloadEngineMultiDownload from "./download-engine/engine/download-engine-multi-download.js";
import { globalCLI } from "./transfer-visualize/transfer-cli/GlobalCLI.js";
import { DownloadEngineRemote } from "./download-engine/engine/DownloadEngineRemote.js";
const DEFAULT_PARALLEL_STREAMS_FOR_NODEJS = 3;
/**
* Download one file with CLI progress
*/
export async function downloadFile(options) {
options.parallelStreams ??= DEFAULT_PARALLEL_STREAMS_FOR_NODEJS;
const downloader = DownloadEngineNodejs.createFromOptions(options);
globalCLI.addDownload(downloader, options);
return await downloader;
}
/**
* Stream events for a download from remote session, doing so by calling `emitRemoteProgress` with the progress info.
* - Supports CLI progress.
*/
export function downloadFileRemote(options) {
const downloader = new DownloadEngineRemote();
globalCLI.addDownload(downloader, options);
return downloader;
}
/**
* Download multiple files with CLI progress
*/
export async function downloadSequence(options, ...downloads) {
let downloadOptions = {};
if (options instanceof BaseDownloadEngine || options instanceof Promise) {
downloads.unshift(options);
}
else if (options) {
downloadOptions = options;
}
const downloader = new DownloadEngineMultiDownload(downloadOptions);
globalCLI.addDownload(downloader, downloadOptions);
await downloader.addDownload(...downloads);
return downloader;
}
//# sourceMappingURL=node-download.js.map