smart-buffer

  • Version 4.2.0
  • Published
  • 138 kB
  • No dependencies
  • MIT license

Install

npm i smart-buffer
yarn add smart-buffer
pnpm add smart-buffer

Overview

smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.

Index

Classes

class SmartBuffer

class SmartBuffer {}

    constructor

    constructor(options?: SmartBufferOptions);
    • Creates a new SmartBuffer instance.

      Parameter options

      The SmartBufferOptions to apply to this instance.

    property encoding

    encoding: any;
    • Sets the string encoding of the SmartBuffer instance.

      Parameter encoding

      The string Buffer encoding to set.

    property internalBuffer

    readonly internalBuffer: any;
    • Gets the underlying internal Buffer. (This includes unmanaged data in the Buffer)

      { Buffer } The Buffer value.

    property length

    length: number;

      property readOffset

      readOffset: number;
      • Sets the read offset value of the SmartBuffer instance.

        Parameter offset

        The offset value to set.

      property writeOffset

      writeOffset: number;
      • Sets the write offset value of the SmartBuffer instance.

        Parameter offset

        The offset value to set.

      method clear

      clear: () => SmartBuffer;
      • Clears the SmartBuffer instance to its original empty state.

      method destroy

      destroy: () => SmartBuffer;
      • Destroys the SmartBuffer instance.

      method fromBuffer

      static fromBuffer: (buff: any, encoding?: any) => SmartBuffer;
      • Creates a new SmartBuffer instance with the provided Buffer and optional encoding.

        Parameter buffer

        The Buffer to use as the internal Buffer value.

        Parameter encoding

        The BufferEncoding to use for strings.

        { SmartBuffer }

      method fromOptions

      static fromOptions: (options: SmartBufferOptions) => SmartBuffer;
      • Creates a new SmartBuffer instance with the provided SmartBufferOptions options.

        Parameter options

        The options to use when creating the SmartBuffer instance.

      method fromSize

      static fromSize: (size: number, encoding?: any) => SmartBuffer;
      • Creates a new SmartBuffer instance with the provided internal Buffer size and optional encoding.

        Parameter size

        The size of the internal Buffer.

        Parameter encoding

        The BufferEncoding to use for strings.

        { SmartBuffer }

      method insertBigInt64BE

      insertBigInt64BE: (value: bigint, offset: number) => SmartBuffer;
      • Inserts a BigInt64BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertBigInt64LE

      insertBigInt64LE: (value: bigint, offset: number) => SmartBuffer;
      • Inserts a Int64LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertBigUInt64BE

      insertBigUInt64BE: (value: bigint, offset: number) => SmartBuffer;
      • Inserts a BigUInt64BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertBigUInt64LE

      insertBigUInt64LE: (value: bigint, offset: number) => SmartBuffer;
      • Inserts a BigUInt64LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertBuffer

      insertBuffer: (value: any, offset: number) => SmartBuffer;
      • Writes a Buffer to the current write position.

        Parameter value

        The Buffer to write.

        Parameter offset

        The offset to write the Buffer to.

        this

      method insertBufferNT

      insertBufferNT: (value: any, offset: number) => SmartBuffer;
      • Inserts a null-terminated Buffer.

        Parameter value

        The Buffer to write.

        Parameter offset

        The offset to write the Buffer to.

        this

      method insertDoubleBE

      insertDoubleBE: (value: number, offset: number) => SmartBuffer;
      • Inserts a DoubleBE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertDoubleLE

      insertDoubleLE: (value: number, offset: number) => SmartBuffer;
      • Inserts a DoubleLE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertFloatBE

      insertFloatBE: (value: number, offset: number) => SmartBuffer;
      • Inserts a FloatBE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertFloatLE

      insertFloatLE: (value: number, offset: number) => SmartBuffer;
      • Inserts a FloatLE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertInt16BE

      insertInt16BE: (value: number, offset: number) => SmartBuffer;
      • Inserts an Int16BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertInt16LE

      insertInt16LE: (value: number, offset: number) => SmartBuffer;
      • Inserts an Int16LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertInt32BE

      insertInt32BE: (value: number, offset: number) => SmartBuffer;
      • Inserts an Int32BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertInt32LE

      insertInt32LE: (value: number, offset: number) => SmartBuffer;
      • Inserts an Int32LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertInt8

      insertInt8: (value: number, offset: number) => SmartBuffer;
      • Inserts an Int8 value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertString

      insertString: (value: string, offset: number, encoding?: any) => SmartBuffer;
      • Inserts a String

        Parameter value

        The String value to insert.

        Parameter offset

        The offset to insert the string at.

        Parameter encoding

        The BufferEncoding to use for writing strings (defaults to instance encoding).

        this

      method insertStringNT

      insertStringNT: (value: string, offset: number, encoding?: any) => SmartBuffer;
      • Inserts a null-terminated String.

        Parameter value

        The String value to write.

        Parameter arg2

        The offset to write the string to, or the BufferEncoding to use.

        Parameter encoding

        The BufferEncoding to use for writing strings (defaults to instance encoding).

        this

      method insertUInt16BE

      insertUInt16BE: (value: number, offset: number) => SmartBuffer;
      • Inserts an UInt16BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertUInt16LE

      insertUInt16LE: (value: number, offset: number) => SmartBuffer;
      • Inserts an UInt16LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertUInt32BE

      insertUInt32BE: (value: number, offset: number) => SmartBuffer;
      • Inserts an UInt32BE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertUInt32LE

      insertUInt32LE: (value: number, offset: number) => SmartBuffer;
      • Inserts an UInt32LE value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method insertUInt8

      insertUInt8: (value: number, offset: number) => SmartBuffer;
      • Inserts an UInt8 value at the given offset value.

        Parameter value

        The value to insert.

        Parameter offset

        The offset to insert the value at.

        this

      method isSmartBufferOptions

      static isSmartBufferOptions: (
      options: SmartBufferOptions
      ) => options is SmartBufferOptions;
      • Type checking function that determines if an object is a SmartBufferOptions object.

      method readBigInt64BE

      readBigInt64BE: (offset?: number) => bigint;
      • Reads a BigInt64BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { BigInt }

      method readBigInt64LE

      readBigInt64LE: (offset?: number) => bigint;
      • Reads a BigInt64LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { BigInt }

      method readBigUInt64BE

      readBigUInt64BE: (offset?: number) => bigint;
      • Reads a BigUInt64BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { BigInt }

      method readBigUInt64LE

      readBigUInt64LE: (offset?: number) => bigint;
      • Reads a BigUInt64LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { BigInt }

      method readBuffer

      readBuffer: (length?: number) => any;
      • Reads a Buffer from the internal read position.

        Parameter length

        The length of data to read as a Buffer.

        { Buffer }

      method readBufferNT

      readBufferNT: () => any;
      • Reads a null-terminated Buffer from the current read poisiton.

        { Buffer }

      method readDoubleBE

      readDoubleBE: (offset?: number) => number;
      • Reads an DoublEBE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readDoubleLE

      readDoubleLE: (offset?: number) => number;
      • Reads an DoubleLE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readFloatBE

      readFloatBE: (offset?: number) => number;
      • Reads an FloatBE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readFloatLE

      readFloatLE: (offset?: number) => number;
      • Reads an FloatLE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readInt16BE

      readInt16BE: (offset?: number) => number;
      • Reads an Int16BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readInt16LE

      readInt16LE: (offset?: number) => number;
      • Reads an Int16LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readInt32BE

      readInt32BE: (offset?: number) => number;
      • Reads an Int32BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readInt32LE

      readInt32LE: (offset?: number) => number;
      • Reads an Int32LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readInt8

      readInt8: (offset?: number) => number;
      • Reads an Int8 value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readString

      readString: (arg1?: number | BufferEncoding, encoding?: any) => string;
      • Reads a String from the current read position.

        Parameter arg1

        The number of bytes to read as a String, or the BufferEncoding to use for the string (Defaults to instance level encoding).

        Parameter encoding

        The BufferEncoding to use for the string (Defaults to instance level encoding).

        { String }

      method readStringNT

      readStringNT: (encoding?: any) => string;
      • Reads a null-terminated String from the current read position.

        Parameter encoding

        The BufferEncoding to use for the string (Defaults to instance level encoding).

        { String }

      method readUInt16BE

      readUInt16BE: (offset?: number) => number;
      • Reads an UInt16BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readUInt16LE

      readUInt16LE: (offset?: number) => number;
      • Reads an UInt16LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readUInt32BE

      readUInt32BE: (offset?: number) => number;
      • Reads an UInt32BE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readUInt32LE

      readUInt32LE: (offset?: number) => number;
      • Reads an UInt32LE value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method readUInt8

      readUInt8: (offset?: number) => number;
      • Reads an UInt8 value from the current read position or an optionally provided offset.

        Parameter offset

        The offset to read data from (optional) { Number }

      method remaining

      remaining: () => number;
      • Gets the remaining data left to be read from the SmartBuffer instance.

        { Number }

      method toBuffer

      toBuffer: () => any;
      • Gets the value of the internal managed Buffer (Includes managed data only)

        Parameter

        { Buffer }

      method toString

      toString: (encoding?: any) => string;
      • Gets the String value of the internal managed Buffer

        Parameter encoding

        The BufferEncoding to display the Buffer as (defaults to instance level encoding).

      method writeBigInt64BE

      writeBigInt64BE: (value: bigint, offset?: number) => SmartBuffer;
      • Writes a BigInt64BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeBigInt64LE

      writeBigInt64LE: (value: bigint, offset?: number) => SmartBuffer;
      • Writes a BigInt64LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeBigUInt64BE

      writeBigUInt64BE: (value: bigint, offset?: number) => SmartBuffer;
      • Writes a BigUInt64BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeBigUInt64LE

      writeBigUInt64LE: (value: bigint, offset?: number) => SmartBuffer;
      • Writes a BigUInt64LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeBuffer

      writeBuffer: (value: any, offset?: number) => SmartBuffer;
      • Writes a Buffer to the current write position.

        Parameter value

        The Buffer to write.

        Parameter offset

        The offset to write the Buffer to.

        this

      method writeBufferNT

      writeBufferNT: (value: any, offset?: number) => SmartBuffer;
      • Writes a null-terminated Buffer.

        Parameter value

        The Buffer to write.

        Parameter offset

        The offset to write the Buffer to.

        this

      method writeDoubleBE

      writeDoubleBE: (value: number, offset?: number) => SmartBuffer;
      • Writes a DoubleBE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeDoubleLE

      writeDoubleLE: (value: number, offset?: number) => SmartBuffer;
      • Writes a DoubleLE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeFloatBE

      writeFloatBE: (value: number, offset?: number) => SmartBuffer;
      • Writes a FloatBE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeFloatLE

      writeFloatLE: (value: number, offset?: number) => SmartBuffer;
      • Writes a FloatLE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeInt16BE

      writeInt16BE: (value: number, offset?: number) => SmartBuffer;
      • Writes an Int16BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeInt16LE

      writeInt16LE: (value: number, offset?: number) => SmartBuffer;
      • Writes an Int16LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeInt32BE

      writeInt32BE: (value: number, offset?: number) => SmartBuffer;
      • Writes an Int32BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeInt32LE

      writeInt32LE: (value: number, offset?: number) => SmartBuffer;
      • Writes an Int32LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeInt8

      writeInt8: (value: number, offset?: number) => SmartBuffer;
      • Writes an Int8 value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeString

      writeString: (
      value: string,
      arg2?: number | BufferEncoding,
      encoding?: any
      ) => SmartBuffer;
      • Writes a String

        Parameter value

        The String value to write.

        Parameter arg2

        The offset to write the string at, or the BufferEncoding to use.

        Parameter encoding

        The BufferEncoding to use for writing strings (defaults to instance encoding).

        this

      method writeStringNT

      writeStringNT: (
      value: string,
      arg2?: number | BufferEncoding,
      encoding?: any
      ) => SmartBuffer;
      • Writes a null-terminated String.

        Parameter value

        The String value to write.

        Parameter arg2

        The offset to write the string to, or the BufferEncoding to use.

        Parameter encoding

        The BufferEncoding to use for writing strings (defaults to instance encoding).

        this

      method writeUInt16BE

      writeUInt16BE: (value: number, offset?: number) => SmartBuffer;
      • Writes an UInt16BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeUInt16LE

      writeUInt16LE: (value: number, offset?: number) => SmartBuffer;
      • Writes an UInt16LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeUInt32BE

      writeUInt32BE: (value: number, offset?: number) => SmartBuffer;
      • Writes an UInt32BE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeUInt32LE

      writeUInt32LE: (value: number, offset?: number) => SmartBuffer;
      • Writes an UInt32LE value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      method writeUInt8

      writeUInt8: (value: number, offset?: number) => SmartBuffer;
      • Writes an UInt8 value to the current write position (or at optional offset).

        Parameter value

        The value to write.

        Parameter offset

        The offset to write the value at.

        this

      Interfaces

      interface SmartBufferOptions

      interface SmartBufferOptions {}
      • Object interface for constructing new SmartBuffer instances.

      property buff

      buff?: Buffer;

        property encoding

        encoding?: BufferEncoding;

          property size

          size?: number;

            Package Files (1)

            Dependencies (0)

            No dependencies.

            Dev Dependencies (13)

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/smart-buffer.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/smart-buffer)
            • HTML
              <a href="https://www.jsdocs.io/package/smart-buffer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>