/** * Unified file abstraction for Grest framework. * Works across HTTP (multipart), WebSocket (base64), and tests (in-memory). * * Single consumption: buffer()/stream()/text() can only be called once. * Use clone() if multiple reads are needed. */ export declare abstract class GGFile { abstract readonly name: string; abstract readonly mimeType: string; abstract readonly size: number; /** * Whether the file content has been consumed. * Once consumed, buffer()/stream()/text() will throw. */ abstract readonly consumed: boolean; /** * Get the file content as a ReadableStream. * Can only be called once per file instance. * @throws Error if already consumed */ abstract stream(): ReadableStream; /** * Get the file content as a Uint8Array. * Can only be called once per file instance. * @throws Error if already consumed */ abstract buffer(): Promise; /** * Get the file content as a UTF-8 string. * Can only be called once per file instance. * @throws Error if already consumed */ abstract text(): Promise; /** * Create a copy of this file that can be consumed independently. * Only works if the file hasn't been consumed yet. * @throws Error if already consumed */ abstract clone(): GGFile; /** * Create a GGFile from a Uint8Array buffer. */ static fromBuffer(data: Uint8Array, name: string, mimeType?: string): GGFile; /** * Create a GGFile from a string (encoded as UTF-8). */ static fromString(content: string, name: string, mimeType?: string): GGFile; /** * Create a GGFile from a base64-encoded string. * Used for WebSocket transport where files are sent as base64. */ static fromBase64(base64: string, name: string, mimeType?: string): GGFile; /** * Convert a GGFile to base64 string. * Consumes the file. */ static toBase64(file: GGFile): Promise; /** * Serialize a GGFile to JSON format for WebSocket transport. * Consumes the file. */ static toJSON(file: GGFile): Promise; /** * Deserialize a GGFile from JSON format. */ static fromJSON(json: GGFileJSON): GGFile; /** * Check if a value is a serialized GGFile JSON. */ static isJSON(value: unknown): value is GGFileJSON; /** * Create a GGFile from a native browser File. * Lazily reads the file content only when buffer()/stream()/text() is called. */ static fromBrowserFile(file: File & { readonly name: string; }): GGFile; } /** * JSON serialization format for GGFile (used in WebSocket transport). */ export interface GGFileJSON { __ggfile: true; name: string; mimeType: string; size: number; data: string; } /** * In-memory implementation of GGFile. * Used for tests and when file content is already fully buffered. */ export declare class BufferGGFile extends GGFile { private _consumed; private readonly data; readonly name: string; readonly mimeType: string; constructor(data: Uint8Array, name: string, mimeType?: string); get size(): number; get consumed(): boolean; protected assertNotConsumed(): void; stream(): ReadableStream; buffer(): Promise; text(): Promise; clone(): GGFile; } /** * Browser implementation of GGFile that wraps a native File/Blob. * Lazily reads file content only when buffer()/stream()/text() is called. */ export declare class BrowserGGFile extends GGFile { private _consumed; private readonly nativeFile; readonly name: string; readonly mimeType: string; readonly size: number; constructor(nativeFile: File & { readonly name: string; }); get consumed(): boolean; private assertNotConsumed; stream(): ReadableStream; buffer(): Promise; text(): Promise; clone(): GGFile; } //# sourceMappingURL=GGFile.d.ts.map