@ende/cbor

ende add jsr:@ende/cbor

Version 2026.10.15 on JSR.

Concise Binary Object Representation (CBOR) is a binary data serialization format optimized for compactness and efficiency. It is designed to encode a wide range of data types, including integers, strings, arrays, and maps, in a space-efficient manner. RFC 8949 - Concise Binary Object Representation (CBOR) spec.

Limitations

  • This implementation only supports the encoding and decoding of "Text String" keys.
  • This implementation encodes decimal numbers with 64 bits. It takes no effort to figure out if the decimal can be encoded with 32 or 16 bits.
  • When decoding, integers with a value below 2 ** 32 will be of type number, with all larger integers being of type bigint.

Functions and classes may have more specific limitations listed.

import { assert, assertEquals } from "@ende/assert";
import { decodeCbor, encodeCbor } from "@ende/cbor";

const rawMessage = "I am a raw Message!";

const encodedMessage = encodeCbor(rawMessage);
const decodedMessage = decodeCbor(encodedMessage);

assert(typeof decodedMessage === "string");
assertEquals(decodedMessage, rawMessage);

Modules

Exports

  • CborArrayDecodedStream — A ReadableStream that wraps the decoded CBOR "Array". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborArrayEncoderStream — A TransformStream that encodes a ReadableStream<CborStreamInput> into CBOR "Indefinite Length Array". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborByteDecodedStream — A ReadableStream that wraps the decoded CBOR "Byte String". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborByteEncoderStream — A TransformStream that encodes a ReadableStream<Uint8Array> into CBOR "Indefinite Length Byte String". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborMapDecodedStream — A ReadableStream that wraps the decoded CBOR "Map". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborMapEncoderStream — A TransformStream that encodes a ReadableStream<CborMapStreamInput> into CBOR "Indefinite Length Map". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborMapStreamInput — Specifies the structure of input for the CborMapEncoderStream.
  • CborMapStreamOutput — Specifies the structure of the output for the CborMapDecodedStream.
  • CborPrimitiveType — This type specifies the primitive types that the implementation can encode/decode into/from.
  • CborSequenceDecoderStream — A TransformStream that decodes a CBOR-sequence-encoded ReadableStream<Uint8Array> into the JavaScript equivalent values represented as ReadableStream<CborStreamOutput>. RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborSequenceEncoderStream — A TransformStream that encodes a ReadableStream<CborStreamInput> into CBOR format sequence. RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborStreamInput — Specifies the encodable value types for the CborSequenceEncoderStream and CborArrayEncoderStream.
  • CborStreamOutput — Specifies the decodable value types for the CborSequenceDecoderStream and CborMapDecodedStream.
  • CborTag — Represents a CBOR tag, which pairs a tag number with content, used to convey additional semantic information in CBOR-encoded data. CBOR Tags.
  • CborTextDecodedStream — A ReadableStream that wraps the decoded CBOR "Text String". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborTextEncoderStream — A TransformStream that encodes a ReadableStream<string> into CBOR "Indefinite Length Text String". RFC 8949 - Concise Binary Object Representation (CBOR)
  • CborType — This type specifies the encodable and decodable values for encodeCbor, decodeCbor, encodeCborSequence, and decodeCborSequence.
  • decodeCbor — Decodes a CBOR-encoded Uint8Array into the JavaScript equivalent values represented as a CborType. RFC 8949 - Concise Binary Object Representation (CBOR)
  • decodeCborSequence — Decodes a CBOR-sequence-encoded Uint8Array into the JavaScript equivalent values represented as a CBorType array. RFC 8949 - Concise Binary Object Representation (CBOR)
  • encodeCbor — Encodes a CborType value into a CBOR format represented as a Uint8Array. RFC 8949 - Concise Binary Object Representation (CBOR)
  • encodeCborSequence — Encodes an array of CborType values into a CBOR format sequence represented as a Uint8Array. RFC 8949 - Concise Binary Object Representation (CBOR)