CborArrayDecodedStream

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

class

class CborArrayDecodedStream extends ReadableStream<CborStreamOutput>

A ReadableStream that wraps the decoded CBOR "Array". 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 {
  CborArrayDecodedStream,
  CborArrayEncoderStream,
  CborSequenceDecoderStream,
} from "@ende/cbor";

const rawMessage = ["a".repeat(100), "b".repeat(100), "c".repeat(100)];

for await (
  const value of ReadableStream.from(rawMessage)
    .pipeThrough(new CborArrayEncoderStream())
    .pipeThrough(new CborSequenceDecoderStream())
) {
  assert(value instanceof CborArrayDecodedStream);
  let i = 0;
  for await (const text of value) {
    assert(typeof text === "string");
    assertEquals(text, rawMessage[i++]);
  }
}

Constructors

constructor

new CborArrayDecodedStream(gen: AsyncGenerator<CborStreamOutput>, releaseLock: ReleaseLock)

Constructs a new instance.

gen: AsyncGenerator<CborStreamOutput>

A AsyncGenerator.

releaseLock: ReleaseLock

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

Source