@playcanvas/splat-transform
Version:
Library and CLI tool for 3D Gaussian splat format conversion and transformation
92 lines (91 loc) • 3.29 kB
TypeScript
/**
* Abstract base class for streaming data from a source.
* Uses a pull-based model where the consumer provides the buffer.
*/
declare abstract class ReadStream {
/**
* Size hint for buffer pre-allocation in readAll().
* May be undefined if size is unknown.
*/
readonly expectedSize: number | undefined;
/**
* Total bytes read from this stream so far.
*/
bytesRead: number;
/**
* @param expectedSize - Optional size hint for buffer pre-allocation
*/
constructor(expectedSize?: number);
/**
* Pull data into the provided buffer.
* @param target - Buffer to fill with data
* @returns Number of bytes read, or 0 for EOF
*/
abstract pull(target: Uint8Array): Promise<number>;
/**
* Read entire stream into a single buffer.
* Uses expectedSize hint if available, grows dynamically if needed.
* @returns Complete data as Uint8Array
*/
readAll(): Promise<Uint8Array>;
/**
* Release resources and abort any pending operations.
*/
close(): void;
}
/**
* Interface representing a readable data source.
* Provides size information and creates streams for reading.
*/
interface ReadSource {
/**
* The size of the source in bytes, or undefined if unknown.
* For compressed sources (e.g., gzipped HTTP), this may be approximate.
*/
readonly size: number | undefined;
/**
* Whether range reads are supported.
* If false, read() must be called with no arguments or start=0.
*/
readonly seekable: boolean;
/**
* Create a stream for reading data, optionally with a byte range.
* @param start - Starting byte offset (inclusive), defaults to 0
* @param end - Ending byte offset (exclusive), defaults to size/EOF
* @returns A ReadStream for pulling data
* @throws Error if range requested on non-seekable source
*/
read(start?: number, end?: number): ReadStream;
/**
* Release any resources held by this source.
*/
close(): void;
}
/**
* Progress callback for tracking read operations.
* @param bytesLoaded - Bytes loaded so far
* @param totalBytes - Total bytes if known, undefined otherwise
*/
type ProgressCallback = (bytesLoaded: number, totalBytes: number | undefined) => void;
/**
* Interface for a file system that can create readable sources.
* Implementations exist for various backends (URL, Node FS, Zip, Memory).
*/
interface ReadFileSystem {
/**
* Create a readable source for the given path/identifier.
* @param filename - Path or identifier for the resource
* @param progress - Optional callback for progress reporting
* @returns Promise resolving to a ReadSource
*/
createSource(filename: string, progress?: ProgressCallback): Promise<ReadSource>;
}
/**
* Read an entire file into memory.
* Convenience helper that handles source creation, reading, and cleanup.
* @param fs - The file system to read from
* @param filename - Path or identifier for the resource
* @returns Promise resolving to file contents as Uint8Array
*/
declare const readFile: (fs: ReadFileSystem, filename: string) => Promise<Uint8Array>;
export { ReadStream, type ReadSource, type ReadFileSystem, type ProgressCallback, readFile };