/// import { BufferProperties } from './buffer-props'; /** * @class * A BufferSlice wraps a buffer of binary data (as an ArrayBuffer). * * The slice is what is represented by the offset and length properties (r/w), * * which can be modified at any time. * * These values are in turn used by the various DataView getters to form the data-representation window. * Those methods have optional arguments that overload the latter values. * * BufferSlice can be deep-copied (except properties), and ArrayBuffer.prototype.slice will be called. See `copy` methods. * * To actually get a clone of a BufferSlice instance with different offset/length window and new properties, * use the `unwrap` method. * * The `unwrap` method is convenient when building zero-copy parsers/demuxers to create new buffer instances * to push to outputs based on one input buffer slice type and the new buffers are simply windows into the input data. * */ export declare class BufferSlice { static allocateNew(byteLength: number): BufferSlice; static mapArrayBuffers(bufferSlices: BufferSlices): ArrayBuffer[]; static fromTypedArray(typedArray: ArrayBufferView, props?: BufferProperties): BufferSlice; /** * Awakes transferable zombies from the dead * * bufferSlice A possibly "dead" BufferSlice that has been * cloned to be transferred into or out of a Worker * and stripped of his methods * @returns A new and alive BufferSlice */ static fromTransferable(bufferSlice: BufferSlice): BufferSlice; /** * original existing BufferSlice representing a data window into an existing ArrayBuffer * @returns a new slice with a newly allocated underlying ArrayBuffer that is a copy of the original slice window data */ static copy(original: BufferSlice): BufferSlice; static write(src: BufferSlice, dest: ArrayBuffer, offset: number): void; static getTotalSize(slices: BufferSlice[], characterSizeBits?: number): number; /** * Metatdata */ props: BufferProperties; /** * Underlying memory handle */ readonly arrayBuffer: ArrayBuffer; /** * Offset into original allocated memory space (ArrayBuffer) */ readonly offset: number; /** * Bytes amount / size i.e number of 8-bit characters */ readonly length: number; constructor(arrayBuffer: ArrayBuffer, offset?: number, length?: number, props?: BufferProperties); /** * characterSizeBits {number} Number of characters needed in a specific encoding (default 8-bit === 1bytes) */ size(characterSizeBits?: number): number; /** * Returns a *new* slice instance around the exact same data buffer with a fresh vanilla properties object (by default), * and the given offset/length window _relative_ to the orignal one (*important*). * * That means that one can only restrain the window from the previous point of view, but not extend it. * Hence the method name. * * The offset is relative and will be added to the original slice one to form the new absolute offset. * The length is arbitrary but can not exceed the length of the original slice (and error will be thrown). * By default (no length passed), the length will correspond to the remainder of the slice based on its new offset. * * Optionally new properties can be passed directly here. * offset length props * @returns new BufferSlice */ unwrap(offset: number, length?: number, props?: BufferProperties): BufferSlice; /** * offsetIncrement Amount of bytes to move front of window forward * @see unwrap called internally, same limitations apply * @returns new BufferSlice */ shrinkFront(offsetIncrement: number): BufferSlice; /** * lengthReduction Amount of bytes to move back of window in retreat * @returns new BufferSlice */ shrinkBack(lengthReduction: number): BufferSlice; /** * Appends the buffer data to this object`s data and returns a new BufferSlice. * @param buffer * @param props * @returns new BufferSlice */ append(buffer: BufferSlice, props?: BufferProperties): BufferSlice; /** * Inverse of `append` method. Prepends the buffer data to this object s data and returns a new BufferSlice. * @param buffer * @param props * @returns new BufferSlice */ prepend(buffer: BufferSlice, props?: BufferProperties): BufferSlice; /** * Copies the slice data and creates a new slice with the same properties. * * @see BufferSlice.copy (static method) */ copy(): BufferSlice; /** * Copies the slice data into an existing buffer at the given offset * @param dest * @param offset * @returns this */ write(dest: ArrayBuffer, offset: number): BufferSlice; /** * Returns an ArrayBufferView for the internal buffer based on the current offset/length of this slice. * * This should be the default method to pass the data slice into nested components for processing. * */ getUint8Array(): Uint8Array; /** * * Returns an ArrayBufferView for the internal buffer based on the current offset/length of this slice. * * This should be the default method to pass the data slice into nested components for deep-analysis or manipulation. * */ getDataView(): DataView; /** * * Creates a view of the slice without copying but exposing the Node.js Buffer interface instead of Uint8Array or ArrayBufferView * * May be an alternative to getUint8Array in certain cases when interacting with Nodejs APIs or streams. * * This might only work on Node.js or browser envs that have a Buffer constructor. * */ getBuffer(): Buffer; /** * allocates a new ArrayBuffer from the current slice */ newArrayBuffer(): ArrayBuffer; toString(): string; } export declare type BufferSlices = BufferSlice[];