Options
All
  • Public
  • Public/Protected
  • All
Menu

A StringBuilder-like object which automatically grows its internal buffer as bytes are added. Uses an ArrayBuffer to store the binary data. Used extensively throughout the project for building up buffers. See GrowableBuffer.grow for an explanation of the growing process.

Hierarchy

Index

Constructors

constructor

Properties

Private buffer

buffer: ArrayBuffer

Private Readonly pausePoints

pausePoints: number[]

Private size

size: number

Accessors

length

  • get length(): number
  • The current number of bytes being occupied. Note that this is NOT the size of the internal buffer.

    Returns number

Methods

add

addAll

grow

  • Grow the internal buffer to hold at least the specified number of bytes. If the internal buffer is too small, it will be resized to size * 2. If the buffer is already sufficiently long, nothing happens. This is called internally when needed, but if a program knows it will need a lot of space eventually, this method can be called explicitly to avoid unnecessary copying.

    Parameters

    • size: number

      An inclusive lower bound on the number of bytes in the internal buffer after the method returns

    Returns GrowableBuffer

pause

  • Pauses the writing process, i.e. bytes added are not written to the underlying output until resume is next called and can be cancelled from being written by calling reset.

    If called multiple times, resume and reset only act on bytes added since the most recent pause. Example:

    let gb = new GrowableBuffer
    gb
      .pause()
        .add(1).add(2).add(3)
        .pause()
          .add(4).add(5).add(6)
          .reset() //cancels [4, 5, 6]
        .resume()
      .resume() //resumes [1, 2, 3]
    console.log(new Uint8Array(gb.toBuffer())) //Uint8Array [ 1, 2, 3 ]
    

    Returns GrowableBuffer

reset

resume

toBuffer

  • toBuffer(): ArrayBuffer
  • Gets the occupied portion in ArrayBuffer form

    Returns ArrayBuffer

    The internal buffer trimmed to this.length

toUint8Array

  • toUint8Array(): Uint8Array
  • Gets the occupied portion in Uint8Array form

    Returns Uint8Array

    The internal buffer trimmed to this.length

Generated using TypeDoc