CborByteDecodedStream

import { CborByteDecodedStream } from "jsr:@ende/cbor";

class

class CborByteDecodedStream extends ReadableStream<Uint8Array>

A ReadableStream that wraps the decoded CBOR "Byte String". RFC 8949 - Concise Binary Object Representation (CBOR)

Instances of this class is created from CborSequenceDecoderStream. This class is not designed for you to create instances of it yourself. It is merely a way for you to validate the type being returned.

Example: Usage

import { assert, assertEquals } from "@ende/assert";
import { concat } from "@ende/bytes";
import {
  CborByteDecodedStream,
  CborByteEncoderStream,
  CborSequenceDecoderStream,
} from "@ende/cbor";

const rawMessage = new Uint8Array(100);

for await (
  const value of ReadableStream.from([rawMessage])
    .pipeThrough(new CborByteEncoderStream())
    .pipeThrough(new CborSequenceDecoderStream())
) {
  assert(value instanceof Uint8Array || value instanceof CborByteDecodedStream);
  if (value instanceof CborByteDecodedStream) {
    assertEquals(concat(await Array.fromAsync(value)), new Uint8Array(100));
  } else assertEquals(value, new Uint8Array(100));
}

Constructors

constructor

new CborByteDecodedStream(gen: AsyncGenerator<Uint8Array>, releaseLock: ReleaseLock)

Constructs a new instance.

gen: AsyncGenerator<Uint8Array>

A AsyncGenerator.

releaseLock: ReleaseLock

A Function that's called when the stream is finished.

Source