UNPKG

node-pkware

Version:

nodejs implementation of StormLib's pkware compressor/de-compressor

88 lines (87 loc) 2.81 kB
import { Buffer } from 'node:buffer'; export declare class ExpandingBuffer { private heap; private startIndex; private endIndex; private readonly backup; constructor(numberOfBytes?: number); /** * Returns the number of bytes in the stored data. */ size(): number; isEmpty(): boolean; /** * Returns the underlying Buffer's (heap) size. */ heapSize(): number; /** * Sets a single byte of the stored data * * If offset is negative, then the method calculates the index from the end backwards */ setByte(offset: number, value: number): void; /** * Adds a single byte to the end of the stored data. * This expands the internal buffer by 0x10_00 bytes if the heap is full */ appendByte(value: number): void; /** * Concatenates a buffer to the end of the stored data. * If the new data exceeds the size of the heap then the internal heap * gets expanded by the integer multiples of 0x1000 bytes */ append(newData: Buffer): void; /** * Returns a slice of data from the internal data. * If no parameters are given then the whole amount of stored data is returned. * Optionally an offset and a limit can be specified: * offset determines the starting position, limit specifies the number of bytes read. * * Watch out! The returned slice of Buffer points to the same Buffer in memory! * This is intentional for performance reasons. */ read(offset?: number, limit?: number): Buffer; /** * Reads a single byte from the stored data */ readByte(offset?: number): number; /** * Does hard delete * * Removes data from the start of the internal buffer (heap) * by copying bytes to lower indices making sure the * startIndex goes back to 0 afterwards */ flushStart(numberOfBytes: number): void; /** * Does hard delete * * Removes data from the end of the internal buffer (heap) * by moving the endIndex back */ flushEnd(numberOfBytes: number): void; /** * Does soft delete * * Removes data from the start of the internal buffer (heap) * by moving the startIndex forward * When the heap gets empty it also resets the indices as a cleanup */ dropStart(numberOfBytes: number): void; /** * Does soft delete * * removes data from the end of the internal buffer (heap) * by moving the endIndex back * When the heap gets empty it also resets the indices as a cleanup */ dropEnd(numberOfBytes: number): void; /** * returns the internal buffer */ getHeap(): Buffer; clear(): void; saveIndices(): void; restoreIndices(): void; private getActualData; }