/** * Shared view tracker for ZIP editing operations. * * This module provides a unified way to track pending edits (set, delete, rename) * for both ZipEditor and ZipFile classes, reducing code duplication. */ import type { ArchiveSource } from "../io/archive-source.js"; import { type ZipPathOptions } from "../zip-spec/zip-path.js"; import type { ZipEntryOptions } from "./index.js"; /** * A "base" entry represents an original entry from the source archive * that should be preserved (possibly renamed). */ export interface BaseViewEntry { kind: "base"; info: TInfo; } /** * Internal representation of a "set" entry (without name, stored as Map key). */ interface InternalSetEntry { kind: "set"; source: ArchiveSource; options?: ZipEntryOptions; } /** * A "set" entry represents a new or updated entry with fresh content. * Returned by getSetEntries() with name derived from Map key. */ export interface SetViewEntry { kind: "set"; name: string; source: ArchiveSource; options?: ZipEntryOptions; } /** * Union type for all view entry kinds (internal storage). */ type InternalViewEntry = BaseViewEntry | InternalSetEntry; /** * Options for ZipEditView. */ export interface ZipEditViewOptions { /** * Path normalization mode. * - `false`: no normalization, names are used as-is * - `ZipPathOptions`: apply normalization rules */ path?: false | ZipPathOptions; } /** * Tracks pending edits to a ZIP archive in a unified manner. * * This class manages: * - Base entries (preserved from original archive) * - Set entries (new or updated content) * - Deletions and renames * * @typeParam TInfo - The type of entry info stored for base entries */ export declare class ZipEditView { private readonly _view; private readonly _pathOptions; private _originalSize; constructor(options?: ZipEditViewOptions); /** * Normalize an entry name according to path options. */ private _normalize; /** * Initialize the view with base entries from an existing archive. * * @param entries - Array of entries with their info * @param getPath - Function to extract the path from entry info */ initFromEntries(entries: readonly TInfo[], getPath: (info: TInfo) => string): void; /** * Check if an entry exists (considering pending edits). */ has(name: string): boolean; /** * Get all output entry names (after applying edits). */ getOutputNames(): string[]; /** * Get the number of entries in the view. */ get size(): number; /** * Iterate over all entries in the view. */ entries(): IterableIterator<[string, InternalViewEntry]>; /** * Get a specific entry by name. */ get(name: string): InternalViewEntry | undefined; /** * Delete an entry from the view. * * @returns `true` if the entry existed and was deleted */ delete(name: string): boolean; /** * Delete a directory and all its contents recursively. * * This method deletes the directory entry itself (if it exists) and all entries * whose paths start with the directory prefix (e.g., "folder/" will delete * "folder/", "folder/file.txt", "folder/sub/file.txt", etc.). * * @param prefix - The directory path prefix to delete (with or without trailing slash) * @returns The number of entries deleted * * @example * ```ts * // Delete "assets/" and all files/folders inside it * const count = view.deleteDirectory("assets"); * // Or with trailing slash (same result) * const count = view.deleteDirectory("assets/"); * ``` */ deleteDirectory(prefix: string): number; /** * Add or update an entry with new content. */ set(name: string, source: ArchiveSource, options?: ZipEntryOptions): void; /** * Rename an entry. * * **Overwrite behavior**: If an entry with the target name already exists, * it will be replaced (similar to `mv -f`). * * @returns `true` if the rename was successful, `false` if source doesn't exist */ rename(from: string, to: string): boolean; /** * Get all base (preserved) entries. */ getBaseEntries(): Array<{ name: string; info: TInfo; }>; /** * Get all set (new/updated) entries. */ getSetEntries(): SetViewEntry[]; /** * Check if there are any pending changes (additions, updates, or deletions). */ hasChanges(): boolean; /** * Clear all entries. */ clear(): void; } export {};