dataview-stream - v2.0.2
    Preparing search index...

    Class DataViewReader

    Treat a Uint8Array as a stream to read typed data from, sequentially. Note that this is not an actual ReadableStream in either the nodejs sense or the web sense.

    Index

    Constructors

    Properties

    BAD_I64: bigint = ...

    Invalid value for reading a signed 64-bit integer. This will allow all bitflags to still be zero while signalling the error. Effectively NaN for 64-bit bigints.

    defaultOptions: RequiredRederOptions = ...

    Accessors

    • get allowTruncation(): boolean

      Is truncation allowed?

      Returns boolean

      Truncation allowed.

    • set allowTruncation(val: boolean): void

      Set truncation mode. May not turn it off, once it's on.

      Parameters

      • val: boolean

      Returns void

    • get finished(): boolean

      Have we read all the bytes yet?

      Returns boolean

      True if finished.

    • get offset(): number

      Current offset.

      Returns number

      Current.

    • get original(): Uint8Array

      Original bytes.

      Returns Uint8Array

      Original.

    • get truncated(): boolean

      If true, truncation is allowed, and this reader has detected truncation.

      Returns boolean

      Truncation state.

    • set truncated(val: boolean): void

      Allowed to be set from outside the class if some higher layer wants to stop all further reads. May only be set to true.

      Parameters

      • val: boolean

      Returns void

    Methods

    • When outputting with console.log('%O', this) or at the node REPL, see the current chunk structure.

      Parameters

      • depth: number

        Current depth.

      • options: InspectOptions

        Options for writing, generated by util.inpect.

      • inspect: Inspect

        Local copy of util.inspect, so there is no node dependency.

      Returns string

      Formatted string.

    • Get a chunk of the buffer as 8-bit ASCII text. This is only useful for ancient protocols such as DNS. If the top bit is set, you get equivalent Unicode characters, which should be Latin-1.

      Advances the current read position by length bytes.

      Parameters

      • length: number

        Number of bytes.

      Returns string

      String.

    • Get a chunk of the original buffer.

      Advances the current read position by length bytes.

      Parameters

      • length: number

        How many bytes?

      Returns Uint8Array

      A subarray of the original buffer, without copying.

    • If the current buffer has not been completely read, throws an error. Does not throw error if truncation is allowed.

      Returns void

      When extra data.

    • Get a half-precision floating point number. On older JS runtimes, uses a local implementation of f16. Returns NaN if truncation is allowed and the packet was truncated.

      Advances the current read position by 2 bytes.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a single-precision floating point number. Returns NaN if truncation is allowed and the packet was truncated.

      Advances the current read position by 4 bytes.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a double-precision floating point number. Returns NaN if truncation is allowed and the packet was truncated.

      Advances the current read position by 8 bytes.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a two-byte signed integer. Advances the current read position by 2 bytes. Returns NaN if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a four-byte signed integer. Advances the current read position by 4 bytes. Returns NaN if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a eight-byte signed integer. Advances the current read position by 8 bytes. Returns DataViewReader.BAD_I64 if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns bigint

      Bigint.

    • Get a signed byte. Advances the current read position by 1 byte. Returns NaN if truncation is allowed and the packet was truncated.

      Returns number

      Number.

    • Reset to the beginning of the input. Ignores the initial offset, so if you want to restart at the same place, call seek(initialOffset). Sets the truncation state back to false.

      Returns void

    • Go to a particular offset in the buffer.

      Parameters

      • offset: number = 0

        The new offset.

      Returns void

      If truncation is allowed, since truncation state would be lost.

    • Skip some number of bytes without manipulating them.

      Parameters

      • length: number

        Number of bytes to skip.

      Returns void

    • Type Parameters

      Parameters

      • description: T

      Returns {
          [K in string | number | symbol]: {
              [K in string | number | symbol as K extends `_${string}` ? never : K]: ReaderType<
                  T[K],
              >
          }[K]
      }

    • Convenience function to repeat reading a given number of times.

      Type Parameters

      Parameters

      • num: number

        Number of times to call fn.

      • fn: (n: number) => T

        Function that reads.

      Returns T[]

      Array of results.

    • Get a two-byte unsigned integer. Advances the current read position by 2 bytes. Returns NaN if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get a four-byte unsigned integer. Advances the current read position by 4 bytes. Returns NaN if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns number

      Number.

    • Get an eight-byte unsigned integer. Advances the current read position by 8 bytes. Returns -1n if truncation is allowed and the packet was truncated.

      Parameters

      • littleEndian: boolean = ...

        Override stream's endianness.

      Returns bigint

      Bigint, since 264 > 253.

    • Get an unsigned byte. Advances the current read position by 1 byte. Returns NaN if truncation is allowed and the packet was truncated.

      Returns number

      Number.

    • All of the bytes that have not been used yet. If complete, returns an empty array.

      Returns Uint8Array

      Byte array.

    • Read a number of bytes as a UTF-8 encoded string. Use the ignoreUTF8errors option to avoid throwing exceptions on invalid UTF-8 and get replacement characters instead. However, by default, Postel was wrong.

      Advances the current read position by length bytes.

      Parameters

      • length: number

        Number of bytes.

      Returns string

      Unicode string.