+6
-11
@@ -1,3 +1,4 @@
|
||||
import { formatBytes } from "@add-ideas/toolbox-helpers";
|
||||
import { ArchivePolicyError } from "./errors";
|
||||
|
||||
export const ARCHIVE_LIMITS = Object.freeze({
|
||||
@@ -18,6 +19,10 @@ export const ARCHIVE_LIMITS = Object.freeze({
|
||||
maxCreateFiles: 5_000,
|
||||
maxCreateBytes: 512 * 1024 * 1024,
|
||||
maxPaxHeaderBytes: 1024 * 1024,
|
||||
maxGzipMembers: 256,
|
||||
maxPasswordBytes: 1_024,
|
||||
maxStructuralHeaderBytes: 16 * 1024 * 1024,
|
||||
maxArchiveHeaderBlocks: 40_000,
|
||||
});
|
||||
|
||||
export function assertFiniteSafeInteger(value: number, label: string): void {
|
||||
@@ -38,17 +43,7 @@ export function assertSourceSize(file: Blob): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number): string {
|
||||
if (!Number.isFinite(bytes)) return "unknown";
|
||||
const units = ["B", "KiB", "MiB", "GiB"];
|
||||
let value = Math.max(0, bytes);
|
||||
let unit = 0;
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024;
|
||||
unit += 1;
|
||||
}
|
||||
return `${value >= 10 || unit === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[unit]}`;
|
||||
}
|
||||
export { formatBytes };
|
||||
|
||||
export function throwIfAborted(signal?: AbortSignal): void {
|
||||
if (signal?.aborted) {
|
||||
|
||||
Reference in New Issue
Block a user