Class CborSequenceDecoderStream
Implements
- TransformStream<Uint8Array, CborStreamOutput>
Index
Constructors
Accessors
Constructors
constructor
- new
Cbor (): CborSequenceDecoderStreamSequence Decoder Stream Constructs a new instance.
Returns CborSequenceDecoderStream
Accessors
readable
- get readable(): ReadableStream<CborStreamOutput>
The ReadableStream
associated with the instance, which provides the decoded CBOR data as CborStreamOutput chunks. Returns ReadableStream<CborStreamOutput>
A ReadableStream
. Example: Usage
import { encodeBase64Url } from "@std/encoding";
import {
CborArrayDecodedStream,
CborArrayEncoderStream,
CborByteDecodedStream,
CborByteEncoderStream,
CborMapDecodedStream,
CborMapEncoderStream,
type CborStreamOutput,
CborSequenceDecoderStream,
CborSequenceEncoderStream,
CborTag,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@std/cbor";
const rawMessage = [
undefined,
null,
true,
false,
3.14,
5,
2n ** 32n,
"Hello World",
new Uint8Array(25),
new Date(),
new CborTag(33, encodeBase64Url(new Uint8Array(7))),
["cake", "carrot"],
{ a: 3, b: "d" },
CborByteEncoderStream.from([new Uint8Array(7)]),
CborTextEncoderStream.from(["Bye!"]),
CborArrayEncoderStream.from([
"Hey!",
CborByteEncoderStream.from([new Uint8Array(18)]),
]),
CborMapEncoderStream.from([
["a", 0],
["b", "potato"],
]),
];
async function logValue(value: CborStreamOutput) {
if (
value instanceof CborByteDecodedStream ||
value instanceof CborTextDecodedStream
) {
for await (const x of value) console.log(x);
} else if (value instanceof CborArrayDecodedStream) {
for await (const x of value) logValue(x);
} else if (value instanceof CborMapDecodedStream) {
for await (const [k, v] of value) {
console.log(k);
logValue(v);
}
} else if (value instanceof CborTag) {
console.log(value);
logValue(value.tagContent);
} else console.log(value);
}
for await (
const value of ReadableStream.from(rawMessage)
.pipeThrough(new CborSequenceEncoderStream())
.pipeThrough(new CborSequenceDecoderStream())
) {
logValue(value);
}
writable
- get writable(): WritableStream<Uint8Array>
The WritableStream
associated with the instance, which accepts Uint8Array chunks to be decoded from CBOR format. Returns WritableStream<Uint8Array>
A WritableStream
. Example: Usage
import { encodeBase64Url } from "@std/encoding";
import {
CborArrayDecodedStream,
CborArrayEncoderStream,
CborByteDecodedStream,
CborByteEncoderStream,
CborMapDecodedStream,
CborMapEncoderStream,
type CborStreamOutput,
CborSequenceDecoderStream,
CborSequenceEncoderStream,
CborTag,
CborTextDecodedStream,
CborTextEncoderStream,
} from "@std/cbor";
const rawMessage = [
undefined,
null,
true,
false,
3.14,
5,
2n ** 32n,
"Hello World",
new Uint8Array(25),
new Date(),
new CborTag(33, encodeBase64Url(new Uint8Array(7))),
["cake", "carrot"],
{ a: 3, b: "d" },
CborByteEncoderStream.from([new Uint8Array(7)]),
CborTextEncoderStream.from(["Bye!"]),
CborArrayEncoderStream.from([
"Hey!",
CborByteEncoderStream.from([new Uint8Array(18)]),
]),
CborMapEncoderStream.from([
["a", 0],
["b", "potato"],
]),
];
async function logValue(value: CborStreamOutput) {
if (
value instanceof CborByteDecodedStream ||
value instanceof CborTextDecodedStream
) {
for await (const x of value) console.log(x);
} else if (value instanceof CborArrayDecodedStream) {
for await (const x of value) logValue(x);
} else if (value instanceof CborMapDecodedStream) {
for await (const [k, v] of value) {
console.log(k);
logValue(v);
}
} else if (value instanceof CborTag) {
console.log(value);
logValue(value.tagContent);
} else console.log(value);
}
for await (
const value of ReadableStream.from(rawMessage)
.pipeThrough(new CborSequenceEncoderStream())
.pipeThrough(new CborSequenceDecoderStream())
) {
logValue(value);
}
A TransformStream that decodes a CBOR-sequence-encoded ReadableStream into the JavaScript equivalent values
represented as ReadableStream.
RFC 8949 - Concise Binary Object Representation (CBOR)
Limitations:
Notice:
Example: Usage