Documentation

cbor

Reads structured data from a CBOR file.

The file must contain a valid CBOR serialization. The CBOR values will be converted into corresponding Typst values as listed in the table below.

The function returns a dictionary, an array or, depending on the CBOR file, another CBOR data type.

Conversion details

CBOR valueConverted into Typst
integerint (or float)
bytesbytes
floatfloat
textstr
boolbool
nullnone
arrayarray
mapdictionary
Typst valueConverted into CBOR
types that can be converted from CBORcorresponding CBOR value
symboltext
contenta map describing the content
other types (length, etc.)text via repr

Notes

Parameters
Question mark

cbor() -> any

source
str or bytes
Required Positional
Question mark

A path to a CBOR file or raw CBOR bytes.

Definitions
Question mark

decode
Warning
cbor.decode is deprecated, directly pass bytes to cbor instead; it will be removed in Typst 0.15.0

Reads structured data from CBOR bytes.

cbor.decode() -> any

data
bytes
Required Positional
Question mark

CBOR data.

encode

Encode structured data into CBOR bytes.

cbor.encode(
any
) -> bytes

value
any
Required Positional
Question mark

Value to be encoded.