Skip to main content

BitStringWriter

The writer class. It is responsible for creating a BitString from a sequence of variable-sized integers.

Index

Constructors

constructor

Methods

flush

  • flush(): string
  • Converts the currently held data into a string and returns it. Resets the internal buffer.


    Returns string

flushBase64

  • flushBase64(): string
  • Converts the currently held data into a base64 string and returns it. Resets the internal buffer.


    Returns string

reset

  • Resets the current writer, discarding any data written so far.


    Returns BitStringWriter

toBase64

  • toBase64(): string
  • Converts the currently held data into a base64 string and returns it. Does not modify the internal buffer.


    Returns string

toBitString

  • toBitString(): string
  • Converts the currently held data into a string and returns it. Does not modify the internal buffer.


    Returns string

writeBit

  • A convenience function for writing a single bit expressed as an integer of value of either 0 or 1.

    With the correct arguments behaves exactly like writeUnsigned(value, 1).

    Any other value passed to this function would result in an error.

    @throws

    when a value not equal to either 0 or 1 is received.


    Parameters

    • value: number

      either 0 or 1.

    Returns BitStringWriter

writeBool

  • A convenience function for writing a single boolean value.

    Coerces value to a boolean, then writes 1 if the result is truthy, 0 otherwise.


    Parameters

    • value: any

    Returns BitStringWriter

writeSigned

  • Writes a signed integer with bits width.

    Throws an Invalid argument error when any of the following is true:

    • bits is outside [0; SAFE_INTEGER_BITS] range;
    • bits bits is not enough to store value.

    Parameters

    • value: number

      a signed integer to be encoded.

    • bits: number

      a non-negative integer. The amount of bits the value should take.

    Returns BitStringWriter

writeUnsigned

  • Writes an unsigned integer with bits width.

    Throws an Invalid argument error when any of the following is true:

    • value is negative;
    • bits is outside [0; SAFE_INTEGER_BITS] range;
    • bits bits is not enough to store value.

    Parameters

    • value: number

      a non-negative integer to be encoded.

    • bits: number

      a non-negative integer. The amount of bits the value should take.

    Returns BitStringWriter