Skip to content

Commit 149d3e5

Browse files
committed
Update README.md
1 parent 489836c commit 149d3e5

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

README.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ microcbor is a minimal JavaScript [CBOR](https://cbor.io/) implementation featur
88

99
- small footprint
1010
- fast performance
11-
- memory-efficient "chunk recycling" streaming encoder
11+
- `Iterable` and `AsyncIterable` streaming APIs with "chunk recycling" encoding option
1212
- [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
1313

1414
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.**
1515

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.
1717

1818
## Table of Contents
1919

@@ -22,7 +22,17 @@ This library is TypeScript-native, ESM-only, and has just one dependency [joeltg
2222
- [API](#api)
2323
- [CBOR Values](#cbor-values)
2424
- [Encoding](#encoding)
25+
- [`EncodeOptions`](#encodeoptions)
26+
- [`encodingLength`](#encodinglength)
27+
- [`encode`](#encode)
28+
- [`encodeIterable`](#encodeiterable)
29+
- [`encodeAsyncIterable`](#encodeasynciterable)
30+
- [`CBOREncoderStream`](#cborencoderstream)
2531
- [Decoding](#decoding)
32+
- [`decode`](#decode)
33+
- [`decodeIterable`](#decodeiterable)
34+
- [`decodeAsyncIterable`](#decodeasynciterable)
35+
- [`CBORDecoderStream`](#cbordecoderstream)
2636
- [Value mapping](#value-mapping)
2737
- [Testing](#testing)
2838
- [Benchmarks](#benchmarks)
@@ -68,6 +78,8 @@ interface CBORMap {
6878

6979
### Encoding
7080

81+
#### `EncodeOptions`
82+
7183
```ts
7284
export interface EncodeOptions {
7385
/**
@@ -92,55 +104,92 @@ export interface EncodeOptions {
92104
*/
93105
minFloatSize?: (typeof FloatSize)[keyof typeof FloatSize]
94106
}
107+
```
95108

109+
#### `encodingLength`
110+
111+
```ts
96112
/**
97113
* Calculate the byte length that a value will encode into
98114
* without actually allocating anything.
99115
*/
100116
declare function encodingLength(value: CBORValue): number
117+
```
118+
119+
#### `encode`
101120

121+
```ts
102122
/**
103123
* Encode a single CBOR value.
104124
* options.chunkRecycling has no effect here.
105125
*/
106126
export function encode(value: CBORValue, options: EncodeOptions = {}): Uint8Array
127+
```
107128

129+
#### `encodeIterable`
130+
131+
```ts
108132
/** Encode an iterable of CBOR values into an iterable of Uint8Array chunks */
109133
export function* encodeIterable(
110134
source: Iterable<CBORValue>,
111135
options: EncodeOptions = {},
112136
): IterableIterator<Uint8Array>
113137
138+
```
139+
140+
#### `encodeAsyncIterable`
141+
142+
```ts
114143
/** Encode an async iterable of CBOR values into an async iterable of Uint8Array chunks */
115144
export async function* encodeAsyncIterable(
116145
source: AsyncIterable<CBORValue>,
117146
options: EncodeOptions = {},
118147
): AsyncIterableIterator<Uint8Array>
119148
149+
```
150+
151+
#### `CBOREncoderStream`
152+
153+
```ts
120154
/**
121155
* Encode a Web Streams API ReadableStream.
122156
* options.chunkRecycling has no effect here.
123157
*/
124158
export class CBOREncoderStream extends TransformStream<CBORValue, Uint8Array> {
125-
public constructor(options: EncodeOptions = {})
159+
public constructor(options: EncodeOptions = {})
126160
}
127161
```
128162

129163
### Decoding
130164

165+
#### `decode`
166+
131167
```ts
132168
/** Decode a single CBOR value. */
133169
export function decode(data: Uint8Array): CBORValue
170+
```
171+
172+
#### `decodeIterable`
134173

174+
```ts
135175
/** Decode an iterable of Uint8Array chunks into an iterable of CBOR values */
136176
export function* decodeIterable(source: Iterable<Uint8Array>): IterableIterator<CBORValue>
137177
178+
```
179+
180+
#### `decodeAsyncIterable`
181+
182+
```ts
138183
/** Decode an async iterable of Uint8Array chunks into an async iterable of CBOR values */
139184
export async function* decodeAsyncIterable(source: AsyncIterable<Uint8Array>): AsyncIterable<CBORValue>
185+
```
186+
187+
#### `CBORDecoderStream`
140188

189+
```ts
141190
/** Decode a Web Streams API ReadableStream. */
142191
export class CBORDecoderStream extends TransformStream<Uint8Array, CBORValue> {
143-
public constructor()
192+
public constructor()
144193
}
145194
```
146195

0 commit comments

Comments
 (0)