Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BufferOutputStream

Wrapper around a single Uint8Array, providing auto-resizing capabilities.

All write operations will append to the internal buffer.

Loosely inspired by Java's ByteArrayOutputStream.

Hierarchy

  • BufferOutputStream

Implements

Index

Constructors

constructor

  • Create a new output stream from a buffer

    Parameters

    • Default value initial: number | Uint8Array = 32

      the initial size for the internal Uint8Array, or buffer to use as source.

    Returns BufferOutputStream

Properties

buffer

buffer: Uint8Array

The buffer to write to

count

count: number

The number of bytes that have been written

Methods

Private ensureCapacity

  • ensureCapacity(min: number): void
  • Ensure that the output stream has enough capacity

    Parameters

    • min: number

      the capacity the buffer should have

    Returns void

getBase64

  • getBase64(): string
  • Return written bytes as a base64 encoded string.

    Returns string

    The base64 encoded string

getBuffer

  • getBuffer(): Uint8Array
  • Return the written bytes as a buffer, sized to the last value written.

    Any modifications to the returned buffer will be reflected in this OutputStream.

    Returns Uint8Array

    A Uint8Array containing all the bytes current written to this OutputStream.

Private grow

  • grow(minCapacity: number): void
  • Grow the buffer up to the next minimum capacity (or higher).

    throws

    If the new capacity exceeds that with which a Uint8Array can be created, an error will be thrown.

    Parameters

    • minCapacity: number

      the minimum capacity required

    Returns void

write

  • write(val: number): void
  • Write a single byte.

    Parameters

    • val: number

      the byte to append

    Returns void

writeInt32

  • writeInt32(val: number): void
  • Write a signed, big-endian 32-bit integer.

    Parameters

    • val: number

      the number to write

    Returns void

writeInt64

  • writeInt64(val: Long): void
  • Write a signed, big-endian 64-bit long.

    Parameters

    • val: Long

      the number to write.

    Returns void

writeInt8

  • writeInt8(val: number): void
  • Write a signed 8-bit integer.

    Parameters

    • val: number

      the number to write

    Returns void

writeMany

  • writeMany(buffer: Uint8Array, offset?: number, length?: number): void
  • Write many bytes.

    The contents of the provided buffer will be copied and appended. The full length of the buffer will be copied, irrespective of byte content.

    Parameters

    • buffer: Uint8Array

      The bytes to append.

    • Default value offset: number = 0
    • Default value length: number = buffer.length

    Returns void

writeString

  • writeString(val: string): void
  • Write a String in UTF-8 format.

    Parameters

    • val: string

      the string value to be appended.

    Returns void

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.