@@ -8,12 +8,12 @@ microcbor is a minimal JavaScript [CBOR](https://cbor.io/) implementation featur
8
8
9
9
- small footprint
10
10
- fast performance
11
- - memory-efficient "chunk recycling" streaming encoder
11
+ - ` Iterable ` and ` AsyncIterable ` streaming APIs with "chunk recycling" encoding option
12
12
- [ Web Streams API] ( https://developer.mozilla.org/en-US/docs/Web/API/Streams_API ) -compatible [ TransformStream] ( https://developer.mozilla.org/en-US/docs/Web/API/TransformStream ) classes
13
13
14
14
microcbor follows the [ deterministic CBOR encoding requirements] ( https://www.rfc-editor.org/rfc/rfc8949.html#core-det ) - all floating-point numbers are serialized in the smallest possible size without losing precision, and object entries are always sorted by key in byte-wise utf-8 lexicographic order. ` NaN ` is always serialized as ` 0xf97e00 ` . ** microcbor doesn't support tags, bigints, typed arrays, non-string keys, or indefinite-length collections.**
15
15
16
- This library is TypeScript-native, ESM-only, and has just one dependency [ joeltg/fp16] ( https://github.com/joeltg/fp16 ) for half-precision floats.
16
+ This library is TypeScript-native, ESM-only, and has just ** one dependency** [ joeltg/fp16] ( https://github.com/joeltg/fp16 ) for half-precision floats.
17
17
18
18
## Table of Contents
19
19
@@ -22,7 +22,17 @@ This library is TypeScript-native, ESM-only, and has just one dependency [joeltg
22
22
- [ API] ( #api )
23
23
- [ CBOR Values] ( #cbor-values )
24
24
- [ Encoding] ( #encoding )
25
+ - [ ` EncodeOptions ` ] ( #encodeoptions )
26
+ - [ ` encodingLength ` ] ( #encodinglength )
27
+ - [ ` encode ` ] ( #encode )
28
+ - [ ` encodeIterable ` ] ( #encodeiterable )
29
+ - [ ` encodeAsyncIterable ` ] ( #encodeasynciterable )
30
+ - [ ` CBOREncoderStream ` ] ( #cborencoderstream )
25
31
- [ Decoding] ( #decoding )
32
+ - [ ` decode ` ] ( #decode )
33
+ - [ ` decodeIterable ` ] ( #decodeiterable )
34
+ - [ ` decodeAsyncIterable ` ] ( #decodeasynciterable )
35
+ - [ ` CBORDecoderStream ` ] ( #cbordecoderstream )
26
36
- [ Value mapping] ( #value-mapping )
27
37
- [ Testing] ( #testing )
28
38
- [ Benchmarks] ( #benchmarks )
@@ -68,6 +78,8 @@ interface CBORMap {
68
78
69
79
### Encoding
70
80
81
+ #### ` EncodeOptions `
82
+
71
83
``` ts
72
84
export interface EncodeOptions {
73
85
/**
@@ -92,55 +104,92 @@ export interface EncodeOptions {
92
104
*/
93
105
minFloatSize? : (typeof FloatSize )[keyof typeof FloatSize ]
94
106
}
107
+ ```
95
108
109
+ #### ` encodingLength `
110
+
111
+ ``` ts
96
112
/**
97
113
* Calculate the byte length that a value will encode into
98
114
* without actually allocating anything.
99
115
*/
100
116
declare function encodingLength(value : CBORValue ): number
117
+ ```
118
+
119
+ #### ` encode `
101
120
121
+ ` ` ` ts
102
122
/**
103
123
* Encode a single CBOR value.
104
124
* options.chunkRecycling has no effect here.
105
125
*/
106
126
export function encode(value: CBORValue, options: EncodeOptions = {}): Uint8Array
127
+ ` ` `
107
128
129
+ #### ` encodeIterable `
130
+
131
+ ` ` ` ts
108
132
/** Encode an iterable of CBOR values into an iterable of Uint8Array chunks */
109
133
export function* encodeIterable(
110
134
source: Iterable<CBORValue>,
111
135
options: EncodeOptions = {},
112
136
): IterableIterator<Uint8Array>
113
137
138
+ ` ` `
139
+
140
+ #### ` encodeAsyncIterable `
141
+
142
+ ` ` ` ts
114
143
/** Encode an async iterable of CBOR values into an async iterable of Uint8Array chunks */
115
144
export async function* encodeAsyncIterable(
116
145
source: AsyncIterable<CBORValue>,
117
146
options: EncodeOptions = {},
118
147
): AsyncIterableIterator<Uint8Array>
119
148
149
+ ` ` `
150
+
151
+ #### ` CBOREncoderStream `
152
+
153
+ ` ` ` ts
120
154
/**
121
155
* Encode a Web Streams API ReadableStream.
122
156
* options.chunkRecycling has no effect here.
123
157
*/
124
158
export class CBOREncoderStream extends TransformStream<CBORValue, Uint8Array> {
125
- public constructor (options : EncodeOptions = {})
159
+ public constructor(options: EncodeOptions = {})
126
160
}
127
161
` ` `
128
162
129
163
### Decoding
130
164
165
+ #### ` decode `
166
+
131
167
` ` ` ts
132
168
/** Decode a single CBOR value. */
133
169
export function decode(data: Uint8Array): CBORValue
170
+ ` ` `
171
+
172
+ #### ` decodeIterable `
134
173
174
+ ` ` ` ts
135
175
/** Decode an iterable of Uint8Array chunks into an iterable of CBOR values */
136
176
export function* decodeIterable(source: Iterable<Uint8Array>): IterableIterator<CBORValue>
137
177
178
+ ` ` `
179
+
180
+ #### ` decodeAsyncIterable `
181
+
182
+ ` ` ` ts
138
183
/** Decode an async iterable of Uint8Array chunks into an async iterable of CBOR values */
139
184
export async function* decodeAsyncIterable(source: AsyncIterable<Uint8Array>): AsyncIterable<CBORValue>
185
+ ` ` `
186
+
187
+ #### ` CBORDecoderStream `
140
188
189
+ ` ` ` ts
141
190
/** Decode a Web Streams API ReadableStream. */
142
191
export class CBORDecoderStream extends TransformStream<Uint8Array, CBORValue> {
143
- public constructor ()
192
+ public constructor()
144
193
}
145
194
` ` `
146
195
0 commit comments