import { Readable } from 'node:stream'; import { F as File, M as MetaStorage, D as DiskStorageOptions, s as HttpError, d as FileInit, e as FilePart, f as FileQuery, O as OperationOptions, g as FileReturn, o as ERRORS, B as BaseStorage, n as DiskStorageWithChecksumOptions } from "../../packem_shared/storage.d-C9EdfTf1.js"; export type { L as LocalMetaStorageOptions } from "../../packem_shared/storage.d-C9EdfTf1.js"; export { L as LocalMetaStorage } from "../../packem_shared/local-meta-storage.d-CYWYyCUo.js"; import 'node:timers'; import 'node:crypto'; import 'node:http'; import 'lru-cache'; /** * 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 checksumTypes: string[]; override readonly supportsRange: boolean; 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 or file already exists and is completed. * @remarks * Supports TTL (time-to-live) option in fileInit. * Creates the file on disk if it doesn't exist. * Returns existing file if it's already completed. */ create(fileInit: FileInit): 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): 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?: 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; }>; /** * 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): 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): 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; protected lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>; private accessCheck; } /** * Additionally calculates checksum of the file/range. */ declare class DiskStorageWithChecksum extends DiskStorage { private hashes; constructor(config: DiskStorageWithChecksumOptions); override delete({ id }: FileQuery): Promise; override write(part: FilePart | FileQuery): Promise; protected override lazyWrite(part: File & FilePart): Promise<[number, ERRORS?]>; } export { DiskStorage, DiskStorageWithChecksum };