UNPKG

idx-data

Version:

An idx binary data format loader.

42 lines (41 loc) 1.69 kB
/// <reference types="node" /> import { BufferType } from './utils'; import { Writable, Readable } from 'stream'; export { BufferType } from './utils'; export declare type BufferTypeString = 'float32' | 'int32' | 'uint8'; /** * @param data A TypedArray containing the data to be written * @param shape The shape of the matrix, each element specifying the size of the corresponding dimension * @param stream A writable stream that the data (including the header) will be written to. * * Writes raw bytes in big endian mode to the writable stream, starting with the idx header. * Writing occurs in batches to reduce memory consumption. */ export declare function writeToStream(data: BufferType, shape: number[], stream: Writable): void; /** * @param data A TypedArray containing the data to be written * @param shape The shape of the matrix, each element specifying the size of the corresponding dimension * @param file The filepath that the data will be written to * * Writes the TypedArray data to file in the IDX format. * Recursively creates the folder path if necessary. */ export declare function saveBits(data: BufferType, shape: number[], file: string): Promise<void>; export interface IdxTensor { data: BufferType; shape: number[]; type: BufferTypeString; } /** * @param stream The stream where the data will be sent * * Listens to the stream and saves incoming data to a TypedArray. */ export declare function readFromStream(stream: Readable): Promise<IdxTensor>; /** * * @param file Filepath that will be read from * * Reads from an IDX formatted binary file into a TypedArray. */ export declare function loadBits(file: string): Promise<IdxTensor>;