/** * Random Access Reader Interface * * Provides an abstraction for reading arbitrary byte ranges from a data source. * This enables efficient access to ZIP archives without downloading the entire file. * * @module */ /** * Interface for reading arbitrary byte ranges from a data source. * * This abstraction allows ZIP parsing to work with: * - Remote HTTP resources (via Range requests) * - Local files (via fs.read with position) * - In-memory buffers (for testing/compatibility) */ export interface RandomAccessReader { /** * Total size of the data source in bytes. * Must be known upfront for ZIP parsing (EOCD is at the end). */ readonly size: number; /** * Read a range of bytes from the data source. * * @param start - Start offset (inclusive, 0-based) * @param end - End offset (exclusive) * @returns The requested bytes */ read(start: number, end: number): Promise; /** * Optional: Close the reader and release resources. */ close?(): Promise; } /** * Options for creating an HTTP Range reader. */ export interface HttpRangeReaderOptions { /** * Custom headers to include in requests. * Useful for authentication tokens, etc. */ headers?: Record; /** * Custom fetch function for testing or custom implementations. * Defaults to global fetch. */ fetch?: typeof globalThis.fetch; /** * Abort signal for cancellation support. */ signal?: AbortSignal; /** * Whether to use credentials (cookies) for cross-origin requests. * @default "same-origin" */ credentials?: NonNullable; /** * Optional: Pre-known file size to skip HEAD request. * If not provided, a HEAD request will be made to determine size. */ size?: number; /** * Whether to validate that the server supports Range requests. * @default true */ validateRangeSupport?: boolean; } /** * Statistics about HTTP Range reader operations. * Useful for debugging and performance monitoring. */ export interface HttpRangeReaderStats { /** Total number of HTTP requests made */ requestCount: number; /** Total bytes downloaded */ bytesDownloaded: number; /** Total file size */ totalSize: number; /** Percentage of file downloaded */ downloadedPercent: number; } /** * Error thrown when the server doesn't support Range requests. */ export { RangeNotSupportedError, HttpRangeError } from "../shared/errors.js"; /** * HTTP Range Reader * * Reads arbitrary byte ranges from a remote HTTP resource using Range requests. * Works in both Node.js (with fetch) and browsers. * * @example * ```ts * const reader = await HttpRangeReader.open("https://example.com/archive.zip"); * console.log(`File size: ${reader.size} bytes`); * * // Read last 22 bytes (minimum EOCD size) * const eocd = await reader.read(reader.size - 22, reader.size); * * // Check stats * console.log(reader.getStats()); * * await reader.close(); * ``` */ export declare class HttpRangeReader implements RandomAccessReader { private readonly url; private readonly headers; private readonly fetchFn; private readonly signal?; private readonly credentials; private _size; private _fullData?; private _requestCount; private _bytesDownloaded; private constructor(); /** * Total size of the remote file in bytes. */ get size(): number; /** * Open a remote ZIP file for random access reading. * * @param url - URL of the ZIP file * @param options - Reader options * @returns A configured HttpRangeReader instance * * @throws {RangeNotSupportedError} If the server doesn't support Range requests * @throws {HttpRangeError} If the HTTP request fails */ static open(url: string, options?: HttpRangeReaderOptions): Promise; /** * Read a range of bytes from the remote file. * * @param start - Start offset (inclusive, 0-based) * @param end - End offset (exclusive) * @returns The requested bytes * * @throws {HttpRangeError} If the HTTP request fails */ read(start: number, end: number): Promise; /** * Get statistics about the reader's operations. */ getStats(): HttpRangeReaderStats; /** * Close the reader. * Currently a no-op but included for interface compliance. */ close(): Promise; } /** * In-memory random access reader. * Wraps a Uint8Array to provide the RandomAccessReader interface. * Useful for testing and as a fallback. */ export declare class BufferReader implements RandomAccessReader { private readonly data; constructor(data: Uint8Array | ArrayBuffer); get size(): number; read(start: number, end: number): Promise; close(): Promise; }