/** Default for RPCClientOptions.maxTransferSize: 1 GiB. */ export declare const DEFAULT_MAX_TRANSFER_SIZE: number; /** * Message types for chunked transfers */ export interface ChunkMessage { id: string; chunkIndex: number; data: Uint8Array; isLast: boolean; } /** * Bytes the buffers of all open transfers may hold together. A client shares * one budget between its managers, so a manager per subscription does not * multiply what a sender can make it allocate. */ export declare class TransferBudget { readonly limit: number; private used; /** * @param limit - Bytes in use at most (0 or undefined: 1 GiB) */ constructor(limit?: number); /** * Bytes reserved right now */ get inUse(): number; /** * Take `bytes`, false when that would exceed the limit */ reserve(bytes: number): boolean; /** * Return bytes taken with reserve() */ release(bytes: number): void; } /** * Split data into chunks */ export declare function createChunks(encoded: Uint8Array, chunkId: string, maxChunkSize: number): Generator; /** * Reassemble chunks back into original data using a buffer of the full size, * allocated with the first chunk. Chunks are written directly to the buffer - * no intermediate Map storage. */ export declare class ChunkAssembler { readonly id: string; private readonly totalSize; private readonly budget?; private buffer?; private receivedChunks; private totalChunks; private chunkSize; private reserved; /** * @param budget - Reserves the buffer with the first chunk; without it nothing is accounted */ constructor(id: string, totalSize: number, totalChunks: number, chunkSize?: number, budget?: TransferBudget | undefined); /** * Add a chunk to the assembler. * Writes directly to the buffer. A duplicate index is ignored. * @returns true if all chunks are received * @throws when the chunk does not fit this transfer (see checkChunk), or * when the budget has no room for the buffer */ addChunk(chunk: ChunkMessage): boolean; /** * Why a chunk does not fit this transfer, or undefined when it does: the * index must lie in [0, totalChunks) and the length must be chunkSize, or * the remainder for the last chunk. */ checkChunk(chunk: ChunkMessage): string | undefined; /** * Check if all chunks have been received */ isComplete(): boolean; /** * Get the reassembled data. * Buffer is already complete, just decode - no copy needed. Chunked * payloads are always full wire messages, so this goes through * decodeMessage: a reassembled CUIB frame yields zero-copy views into * the assembly buffer. */ getData(): T; /** * Return the bytes reserved for the buffer to the budget */ release(): void; /** * Get progress information */ getProgress(): { received: number; total: number; percentage: number; }; private allocate; } /** * Manager for handling multiple chunk transfers. * * A header is checked before anything is allocated, at most `maxTransfers` * transfers run at once, and a transfer without a chunk for 30 s is dropped * by a timer that only runs while transfers exist. A transfer reserves its * buffer in the budget with its first chunk and is dropped when the budget * has no room left. A chunk that does not fit drops its whole transfer. */ export declare class ChunkingManager { private readonly maxTransfers; private transfers; private sweepTimer?; private maxTransferSize; private budget; /** * @param maxTransferSize - Largest accepted totalSize in bytes (0 or undefined: 1 GiB) * @param maxTransfers - Most transfers open at once, further headers are refused (default 32) * @param budget - Bytes the buffers of open transfers may hold, shared with other managers (default: an own budget of maxTransferSize) */ constructor(maxTransferSize?: number, maxTransfers?: number, budget?: TransferBudget); /** * Start receiving chunks for a transfer. The buffer is allocated with the * first chunk. A header that does not describe a valid transfer, or one * beyond the transfer cap, is reported through onError. */ startReceiving(id: string, totalChunks: number, onComplete: (data: any) => void, onError: (error: Error) => void, totalSize: number, chunkSize?: number): void; /** * Process an incoming chunk. A chunk for an unknown transfer is ignored, a * duplicate of the right length too (the first copy wins). A chunk that * does not fit its transfer drops the transfer and is reported through * onError once; later chunks of that id count as unknown. */ processChunk(chunk: ChunkMessage): void; /** * Cancel a transfer */ cancel(id: string): void; /** * Drop a transfer without reporting it, e.g. when nobody waits for it anymore. */ discard(id: string): void; /** * Drop every transfer without reporting it and stop the sweep timer. */ dispose(): void; /** * Number of open transfers */ get size(): number; /** * Get progress for a transfer */ getProgress(id: string): { received: number; total: number; percentage: number; } | null; private checkHeader; private remove; private armSweep; private sweepStale; } /** * Parse an `x-chunk-index` header. Anything but a plain decimal integer * yields NaN, which the assembler rejects. */ export declare function parseChunkIndex(raw: string | null | undefined): number;