UNPKG

beth-parser

Version:

Parser library for Bethesda's Creation Engine data files

48 lines (47 loc) 1.3 kB
/// <reference types="node" /> import DataSource from "./DataSource"; /** * Node.js based file data source using single internal read buffer. * * When specifying internal buffer size (i.e. not relying on the default value), keep in mind that * every read request that can't fit inside that buffer will result in a new buffer allocation. */ export default class FileSource implements DataSource { /** * File descriptor. */ private fileDesc; /** * Current read position. */ private filePosition; /** * Source data buffer. */ private sourceBuffer; /** * Cursor position inside source buffer. */ private bufferOffset; /** * Actual data length inside source buffer. */ private bufferLength; /** * @param path Source file path. * @param bufferSize Size of the internal source buffer. */ constructor(path: string, bufferSize?: number); /** * Read another portion of the file into the target buffer. */ private readFile; /** * Read data using the internal source buffer. */ private readBuffer; read(length: number): Buffer; skip(length: number): void; close(): void; cursor(): number; }