import { Readable, Transform } from 'node:stream'; import { F as File, C as ConditionalSupport, M as MetaStorage, D as DiskStorageOptions, e as FileInit, g as ConditionalOptions, O as OperationOptions, h as FilePart, i as FileQuery, c as FileReturn, S as StoredObject, j as CopyConditionalOptions, o as ERRORS, B as BaseStorage, n as DiskStorageWithChecksumOptions } from "../../packem_shared/storage.d-Cnjmzau5.js"; export type { L as LocalMetaStorageOptions } from "../../packem_shared/storage.d-Cnjmzau5.js"; import { b as HttpError } from "../../packem_shared/types.d-DFh9698o.js"; export { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-DuAe8gC_.js"; import 'lru-cache'; import 'node:crypto'; import 'node:http'; /** * Local disk-based storage implementation. * @template TFile The file type used by this storage backend. * @remarks * ## Error Handling * - Filesystem operations throw errors directly (no retry logic) * - File not found errors are thrown immediately * - Permission errors are propagated as-is * * ## Retry Behavior * - No automatic retries (filesystem operations are typically immediate) * - Errors are thrown directly for immediate feedback * * ## File Paths * - Files are stored in the configured directory * - Metadata files use the `.META` suffix by default * - File paths are resolved relative to the storage directory */ declare class DiskStorage extends BaseStorage { static override readonly name: string; override readonly storageKind: string; override checksumTypes: string[]; override readonly supportsRange: boolean; /** * Predicates are compared under the storage lock of the key, and a conditional upload lands * through an atomic rename. The lock is process-local: writers in another process are not * excluded. */ override readonly conditionalSupport: ConditionalSupport; override get raw(): { directory: string; }; directory: string; meta: MetaStorage; constructor(config: DiskStorageOptions); /** * Normalizes errors with disk storage context. * @param error The error to normalize. * @returns Normalized HTTP error. */ override normalizeError(error: Error): HttpError; /** * Creates a new file upload and saves its metadata. * @param fileInit File initialization configuration. * @returns Promise resolving to the created file object. * @throws {Error} If validation fails. * @remarks * Supports TTL (time-to-live) option in fileInit. * An upload already stored under the same id is replaced: its content is discarded and the * new upload starts empty. */ create(fileInit: FileInit, options?: ConditionalOptions & OperationOptions): Promise; /** * Writes data to a file upload. * @param part File part containing data to write, file query, or full file object. * @returns Promise resolving to the updated file object. * @throws {Error} If file is expired (ERRORS.GONE), locked (ERRORS.FILE_LOCKED), or conflicts occur (ERRORS.FILE_CONFLICT). * @remarks * Supports chunked uploads with start position. * Automatically detects file type from stream on first chunk if contentType is not set. * Validates checksum algorithms if provided. * Uses file locking to prevent concurrent writes. * Updates file status to "completed" when all bytes are written. */ write(part: FilePart | FileQuery | TFile, options?: ConditionalOptions & OperationOptions): Promise; /** * Store the body of a conditional upload in a sibling file, then — still under the key's lock — * check the predicate and rename it over the target. A failed predicate leaves the target and * its record untouched. */ private writeConditional; /** * Strong ETag of the file stored under `name` (the one {@link DiskStorage.get} reports), or * `undefined` when there is none. */ private eTagOf; protected override currentETag(file: TFile): Promise; /** * Gets an uploaded file by ID. * @param query File query containing the file ID to retrieve. * @param query.id File ID to retrieve. * @returns Promise resolving to the file data including content buffer. * @throws {Error} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE). * @remarks * Loads the entire file content into memory as a Buffer. * For large files, consider using getStream() instead. * Includes ETag (MD5 hash) for content verification. */ get({ id }: FileQuery, options?: ConditionalOptions & OperationOptions & { range?: { end?: number; start: number; }; }): Promise; /** * Checks if a file exists by verifying both metadata and the actual filesystem file. * Returns true only if both the metadata and the file exist. * @param query File query containing the file ID to check. * @returns Promise resolving to true if both metadata and file exist, false otherwise. */ override exists({ id }: FileQuery): Promise; /** * Gets an uploaded file as a readable stream for efficient large file handling. * @param query File query containing the file ID to stream. * @param query.id File ID to stream. * @returns Promise resolving to an object containing the stream, headers, and size. * @throws {UploadError} If the file cannot be found (ERRORS.FILE_NOT_FOUND) or has expired (ERRORS.GONE). * @remarks Creates a readable stream directly from the file system for efficient memory usage. */ override getStream({ id }: FileQuery): Promise<{ headers?: Record; size?: number; stream: Readable; }>; protected override statObject(id: string): Promise; /** * Deletes an upload and its metadata. * @param query File query containing the file ID to delete. * @param query.id File ID to delete. * @returns Promise resolving to the deleted file object with status: "deleted". * @throws {UploadError} If the file metadata cannot be found. */ delete({ id }: FileQuery, options?: ConditionalOptions & OperationOptions): Promise; /** * Renames the staged file over the upload's, which replaces it in one step. */ protected override commitReplacement(id: string, config: FileInit, staged: TFile): Promise; /** * Copies an upload file to a new location. * @param name Source file name/ID. * @param destination Destination file name/ID. * @returns Promise resolving to the copied file object. * @throws {UploadError} If the source file cannot be found. */ copy(name: string, destination: string, options?: CopyConditionalOptions & OperationOptions): Promise; /** * Moves an upload file to a new location. * @param name Source file name/ID. * @param destination Destination file name/ID. * @returns Promise resolving to the moved file object. * @throws {Error} If the source file cannot be found. */ move(name: string, destination: string): Promise; /** * Retrieves a list of uploaded files. * @returns Promise resolving to an array of file metadata objects. * @remarks Walks the storage directory and returns all files, excluding metadata files. */ override list(): Promise; /** * Returns the absolute on-disk path for the uploaded file, always rooted at * `this.directory`. Absolute inputs and `..` traversals are rejected. */ protected getFilePath(filename: string): string; /** * Streams the part body to disk at `part.start`. * @param part The part to write * @param transforms Extra transforms the body passes through before it lands on disk * @returns The offset after the write, or NaN with an error code when the write failed. An * aborted checksum-less write keeps what it stored: its offset is `start` plus the bytes this * write delivered, never the file's size, which later chunks may already have extended. */ protected lazyWrite(part: File & FilePart, transforms?: Transform[]): Promise<[number, ERRORS?]>; /** * Runs `function_` under the key's lock, waiting briefly while another request holds it: the * lock fails fast, and a conditional read or delete must not answer 423 for a concurrent one. * @param key Lock key * @param function_ Work to do under the lock * @returns What `function_` returns */ private withLockWhenFree; private accessCheck; } /** * Additionally calculates checksum of the file/range. `checksum: false` turns that off, leaving a * plain {@link DiskStorage}. */ declare class DiskStorageWithChecksum extends DiskStorage { private readonly hashes?; constructor(config: DiskStorageWithChecksumOptions); override delete(query: FileQuery, options?: ConditionalOptions & OperationOptions): Promise; /** * Records the hash of the bytes stored so far with every save of an upload's metadata. */ override saveMeta(file: TFile): Promise; protected override lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>; } export { DiskStorage, DiskStorageWithChecksum };