Comparing version 3.0.2 to 3.0.3
@@ -12,3 +12,4 @@ import { downloadFileBrowser, DownloadFileBrowserOptions, downloadSequenceBrowser } from "./download/browser-download.js"; | ||
import { FormattedStatus } from "./download/transfer-visualize/format-transfer-status.js"; | ||
import DownloadEngineMultiDownload from "./download/download-engine/engine/download-engine-multi-download.js"; | ||
export { downloadFileBrowser, downloadSequenceBrowser, EmptyResponseError, StatusCodeError, XhrError, InvalidContentLengthError, FetchStreamError, IpullError, EngineError }; | ||
export type { DownloadFileBrowserOptions, DownloadEngineBrowser, FormattedStatus, SaveProgressInfo }; | ||
export type { DownloadFileBrowserOptions, DownloadEngineBrowser, DownloadEngineMultiDownload, FormattedStatus, SaveProgressInfo }; |
import DownloadEngineBrowser, { DownloadEngineOptionsBrowser } from "./download-engine/engine/download-engine-browser.js"; | ||
import DownloadEngineMultiDownload from "./download-engine/engine/download-engine-multi-download.js"; | ||
export declare const DEFAULT_PARALLEL_STREAMS_FOR_BROWSER = 3; | ||
export type DownloadFileBrowserOptions = DownloadEngineOptionsBrowser; | ||
@@ -5,0 +4,0 @@ /** |
import DownloadEngineBrowser from "./download-engine/engine/download-engine-browser.js"; | ||
import DownloadEngineMultiDownload from "./download-engine/engine/download-engine-multi-download.js"; | ||
export const DEFAULT_PARALLEL_STREAMS_FOR_BROWSER = 3; | ||
const DEFAULT_PARALLEL_STREAMS_FOR_BROWSER = 3; | ||
/** | ||
@@ -15,5 +15,4 @@ * Download one file in the browser environment. | ||
export async function downloadSequenceBrowser(...downloads) { | ||
const allDownloads = await Promise.all(downloads); | ||
return new DownloadEngineMultiDownload(allDownloads); | ||
return await DownloadEngineMultiDownload.fromEngines(downloads); | ||
} | ||
//# sourceMappingURL=browser-download.js.map |
@@ -38,2 +38,3 @@ import { DownloadFile, SaveProgressInfo } from "../types.js"; | ||
get status(): import("../../transfer-visualize/format-transfer-status.js").FormattedStatus; | ||
get downloadStatues(): import("../../transfer-visualize/format-transfer-status.js").FormattedStatus[]; | ||
/** | ||
@@ -40,0 +41,0 @@ * @internal |
@@ -28,2 +28,5 @@ import UrlInputError from "./error/url-input-error.js"; | ||
} | ||
get downloadStatues() { | ||
return [this.status]; | ||
} | ||
/** | ||
@@ -30,0 +33,0 @@ * @internal |
@@ -18,3 +18,3 @@ import BaseDownloadEngine, { BaseDownloadEngineEvents } from "./base-download-engine.js"; | ||
protected _closeFiles: (() => Promise<void>)[]; | ||
constructor(engines: (DownloadEngineMultiAllowedEngines | DownloadEngineMultiDownload)[]); | ||
protected constructor(engines: (DownloadEngineMultiAllowedEngines | DownloadEngineMultiDownload)[]); | ||
get downloadStatues(): (FormattedStatus | ProgressStatusWithIndex)[]; | ||
@@ -30,3 +30,4 @@ get downloadSize(): number; | ||
protected static _extractEngines<Engine>(engines: Engine[]): any[]; | ||
static fromEngines<Engine extends DownloadEngineMultiAllowedEngines>(engines: (Engine | Promise<Engine>)[]): Promise<DownloadEngineMultiDownload<DownloadEngineMultiAllowedEngines>>; | ||
} | ||
export {}; |
@@ -94,3 +94,6 @@ import BaseDownloadEngine from "./base-download-engine.js"; | ||
} | ||
static async fromEngines(engines) { | ||
return new DownloadEngineMultiDownload(await Promise.all(engines)); | ||
} | ||
} | ||
//# sourceMappingURL=download-engine-multi-download.js.map |
import DownloadEngineNodejs, { DownloadEngineOptionsNodejs } 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 { AvailableCLIProgressStyle } from "./transfer-visualize/transfer-cli/progress-bars/switch-cli-progress-style.js"; | ||
import { CliFormattedStatus } from "./transfer-visualize/transfer-cli/progress-bars/base-transfer-cli-progress-bar.js"; | ||
export declare const DEFAULT_PARALLEL_STREAMS_FOR_NODEJS = 3; | ||
export declare const DEFAULT_CLI_STYLE: AvailableCLIProgressStyle; | ||
export type CliProgressDownloadEngineOptions = { | ||
truncateName?: boolean | number; | ||
cliProgress?: boolean; | ||
cliStyle?: AvailableCLIProgressStyle | ((status: CliFormattedStatus) => string); | ||
cliName?: string; | ||
cliAction?: string; | ||
}; | ||
import { CliProgressDownloadEngineOptions } from "./transfer-visualize/transfer-cli/cli-animation-wrapper.js"; | ||
export type DownloadFileOptions = DownloadEngineOptionsNodejs & CliProgressDownloadEngineOptions; | ||
@@ -16,0 +6,0 @@ /** |
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 TransferCli from "./transfer-visualize/transfer-cli/transfer-cli.js"; | ||
import switchCliProgressStyle from "./transfer-visualize/transfer-cli/progress-bars/switch-cli-progress-style.js"; | ||
export const DEFAULT_PARALLEL_STREAMS_FOR_NODEJS = 3; | ||
export const DEFAULT_CLI_STYLE = "fancy"; | ||
function createCliProgressForDownloadEngine(options) { | ||
const cliOptions = { ...options }; | ||
if (options.cliAction) { | ||
cliOptions.action = options.cliAction; | ||
} | ||
if (options.cliName) { | ||
cliOptions.name = options.cliName; | ||
} | ||
cliOptions.createProgressBar = typeof options.cliStyle === "function" ? | ||
options.cliStyle : | ||
switchCliProgressStyle(options.cliStyle ?? DEFAULT_CLI_STYLE, { truncateName: options.truncateName }); | ||
return new TransferCli(cliOptions); | ||
} | ||
import CliAnimationWrapper from "./transfer-visualize/transfer-cli/cli-animation-wrapper.js"; | ||
import { CLI_LEVEL } from "./transfer-visualize/transfer-cli/transfer-cli.js"; | ||
const DEFAULT_PARALLEL_STREAMS_FOR_NODEJS = 3; | ||
/** | ||
@@ -25,20 +11,7 @@ * Download one file with CLI progress | ||
export async function downloadFile(options) { | ||
let cli; | ||
if (options.cliProgress) { | ||
options.cliAction ??= options.fetchStrategy === "localFile" ? "Copying" : "Downloading"; | ||
cli = createCliProgressForDownloadEngine(options); | ||
cli.startLoading(); | ||
} | ||
options.parallelStreams ??= DEFAULT_PARALLEL_STREAMS_FOR_NODEJS; | ||
const downloader = await DownloadEngineNodejs.createFromOptions(options); | ||
if (cli) { | ||
cli.start(); | ||
downloader.on("progress", () => { | ||
cli?.updateStatues([downloader.status]); | ||
}); | ||
downloader.on("closed", () => { | ||
cli?.stop(); | ||
}); | ||
} | ||
return downloader; | ||
const downloader = DownloadEngineNodejs.createFromOptions(options); | ||
const wrapper = new CliAnimationWrapper(downloader, options); | ||
await wrapper.attachAnimation(); | ||
return await downloader; | ||
} | ||
@@ -56,23 +29,8 @@ /** | ||
} | ||
let cli; | ||
if (downloadOptions.cliProgress) { | ||
if (downloadOptions.fetchStrategy) { | ||
downloadOptions.cliAction ??= downloadOptions.fetchStrategy === "localFile" ? "Copying" : "Downloading"; | ||
} | ||
cli = createCliProgressForDownloadEngine(downloadOptions); | ||
cli.startLoading(); | ||
} | ||
const allDownloads = await Promise.all(downloads); | ||
const oneDownloader = new DownloadEngineMultiDownload(allDownloads); | ||
if (cli) { | ||
cli.start(); | ||
oneDownloader.on("progress", () => { | ||
cli?.updateStatues(oneDownloader.downloadStatues); | ||
}); | ||
oneDownloader.on("closed", () => { | ||
cli?.stop(); | ||
}); | ||
} | ||
return oneDownloader; | ||
downloadOptions.cliLevel = CLI_LEVEL.HIGH; | ||
const downloader = DownloadEngineMultiDownload.fromEngines(downloads); | ||
const wrapper = new CliAnimationWrapper(downloader, downloadOptions); | ||
await wrapper.attachAnimation(); | ||
return await downloader; | ||
} | ||
//# sourceMappingURL=node-download.js.map |
import prettyBytes from "pretty-bytes"; | ||
import prettyMilliseconds from "pretty-ms"; | ||
const DEFAULT_LOCALIZATION = "en-US"; | ||
const NUMBER_FORMAT_OPTIONS = { | ||
@@ -14,3 +15,3 @@ maximumFractionDigits: 2, | ||
}; | ||
const PRETTY_BYTES_OPTIONS = { ...NUMBER_FORMAT_OPTIONS, space: false }; | ||
const PRETTY_BYTES_OPTIONS = { ...NUMBER_FORMAT_OPTIONS, space: false, locale: DEFAULT_LOCALIZATION }; | ||
const DEFAULT_CLI_INFO_STATUS = { | ||
@@ -37,3 +38,3 @@ speed: 0, | ||
const formatTimeLeft = prettyMilliseconds(fullStatus.timeLeft, PRETTY_MS_OPTIONS); | ||
const formattedPercentage = fullStatus.percentage.toLocaleString(undefined, { | ||
const formattedPercentage = fullStatus.percentage.toLocaleString(DEFAULT_LOCALIZATION, { | ||
minimumIntegerDigits: 1, | ||
@@ -40,0 +41,0 @@ minimumFractionDigits: 4 |
@@ -17,8 +17,13 @@ import UpdateManager from "stdout-update"; | ||
export declare const DEFAULT_TRANSFER_CLI_OPTIONS: TransferCliOptions; | ||
export declare enum CLI_LEVEL { | ||
LOW = 0, | ||
HIGH = 2 | ||
} | ||
export default class TransferCli { | ||
protected readonly loadingAnimation: CliSpinnersLoadingAnimation; | ||
static activeCLILevel: CLI_LEVEL; | ||
readonly loadingAnimation: CliSpinnersLoadingAnimation; | ||
protected options: TransferCliOptions; | ||
protected stdoutManager: UpdateManager; | ||
constructor(options: Partial<TransferCliOptions>); | ||
startLoading(): void; | ||
protected myCLILevel: number; | ||
constructor(options: Partial<TransferCliOptions>, myCLILevel?: CLI_LEVEL); | ||
start(): void; | ||
@@ -25,0 +30,0 @@ stop(): void; |
@@ -14,7 +14,15 @@ import UpdateManager from "stdout-update"; | ||
}; | ||
export var CLI_LEVEL; | ||
(function (CLI_LEVEL) { | ||
CLI_LEVEL[CLI_LEVEL["LOW"] = 0] = "LOW"; | ||
CLI_LEVEL[CLI_LEVEL["HIGH"] = 2] = "HIGH"; | ||
})(CLI_LEVEL || (CLI_LEVEL = {})); | ||
export default class TransferCli { | ||
static activeCLILevel = CLI_LEVEL.LOW; | ||
loadingAnimation; | ||
options; | ||
stdoutManager = UpdateManager.getInstance(); | ||
constructor(options) { | ||
myCLILevel; | ||
constructor(options, myCLILevel = CLI_LEVEL.LOW) { | ||
TransferCli.activeCLILevel = this.myCLILevel = myCLILevel; | ||
this.options = { ...DEFAULT_TRANSFER_CLI_OPTIONS, ...options }; | ||
@@ -29,7 +37,3 @@ this.updateStatues = debounce(this.updateStatues.bind(this), this.options.debounceWait, { | ||
} | ||
startLoading() { | ||
this.loadingAnimation.start(); | ||
} | ||
start() { | ||
this.loadingAnimation.stop(); | ||
this.stdoutManager.hook(); | ||
@@ -39,3 +43,2 @@ process.on("exit", this.stop); | ||
stop() { | ||
this.stdoutManager.erase(); | ||
this.stdoutManager.unhook(false); | ||
@@ -45,2 +48,5 @@ process.off("exit", this.stop); | ||
updateStatues(statues) { | ||
if (this.myCLILevel !== TransferCli.activeCLILevel) { | ||
return; // Do not update if there is a higher level CLI, meaning that this CLI is sub-CLI | ||
} | ||
const newLog = statues.map((status) => { | ||
@@ -47,0 +53,0 @@ status.transferAction = this.options.action ?? status.transferAction; |
@@ -13,3 +13,4 @@ import DownloadEngineNodejs from "./download/download-engine/engine/download-engine-nodejs.js"; | ||
import { FormattedStatus } from "./download/transfer-visualize/format-transfer-status.js"; | ||
import DownloadEngineMultiDownload from "./download/download-engine/engine/download-engine-multi-download.js"; | ||
export { downloadFile, downloadSequence, PathNotAFileError, EmptyResponseError, StatusCodeError, XhrError, InvalidContentLengthError, FetchStreamError, IpullError, EngineError }; | ||
export type { DownloadFileOptions, DownloadSequenceOptions, DownloadEngineNodejs, SaveProgressInfo, FormattedStatus }; | ||
export type { DownloadFileOptions, DownloadSequenceOptions, DownloadEngineNodejs, DownloadEngineMultiDownload, SaveProgressInfo, FormattedStatus }; |
{ | ||
"name": "ipull", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "The only file downloader you'll ever need. For node.js and the browser, CLI and library for fast and reliable file downloads.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217211
159
2893