cbor-x 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/decode.js +18 -12
- package/dist/decode-no-eval.cjs +1137 -0
- package/dist/decode-no-eval.cjs.map +1 -0
- package/dist/index-no-eval.cjs +2376 -0
- package/dist/index-no-eval.cjs.map +1 -0
- package/dist/index-no-eval.min.js +2 -0
- package/dist/index-no-eval.min.js.map +1 -0
- package/dist/index.js +511 -341
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -140
- package/dist/index.min.js.map +1 -0
- package/dist/node.cjs +518 -346
- package/dist/node.cjs.map +1 -0
- package/dist/test.js +172 -31
- package/dist/test.js.map +1 -0
- package/encode.d.ts +1 -1
- package/encode.js +165 -2
- package/index.d.ts +9 -5
- package/index.js +1 -1
- package/node-index.js +1 -1
- package/package.json +7 -6
- package/rollup.config.js +51 -8
- package/stream.js +4 -2
package/README.md
CHANGED
|
@@ -52,6 +52,26 @@ receivingStream.on('data', (data) => {
|
|
|
52
52
|
```
|
|
53
53
|
The `EncoderStream` and `DecoderStream` instances will have also the record structure extension enabled by default (see below).
|
|
54
54
|
|
|
55
|
+
### Iterables
|
|
56
|
+
In addition to using CBOR with streams, CBOR can also encode to an iterable that can be iterated as a sequence of binary chunks with `encodeAsIterable`, which facilitates progressive encoding:
|
|
57
|
+
```JavaScript
|
|
58
|
+
import { encodeAsIterable } from 'cbor-x';
|
|
59
|
+
|
|
60
|
+
for (let binaryChunk of encodeAsIterable(data)){
|
|
61
|
+
// progressively get binary chunks as data is encoded
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
And `encodeAsAsyncIterable` is also available, which returns an async iterable, and can be used to encode data from async iterables as well as Blob data.
|
|
65
|
+
|
|
66
|
+
```JavaScript
|
|
67
|
+
import { encodeAsAsyncIterable } from 'cbor-x';
|
|
68
|
+
|
|
69
|
+
let data = { blob: new Blob(...) };
|
|
70
|
+
for await (let binaryChunk of encodeAsAsyncIterable(data)){
|
|
71
|
+
// progressively get binary chunks as asynchronous data source is encoded
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
55
75
|
## Deno Usage
|
|
56
76
|
Cbor-x modules are standard ESM modules and can be loaded directly from the [deno.land registry for cbor](https://deno.land/x/cbor) for use in Deno. The standard pack/encode and unpack/decode functionality is available on Deno, like other platforms.
|
|
57
77
|
|
package/decode.js
CHANGED
|
@@ -197,6 +197,7 @@ export function checkedRead() {
|
|
|
197
197
|
}
|
|
198
198
|
// bundled strings to skip past
|
|
199
199
|
position = bundledStrings.postBundlePosition;
|
|
200
|
+
bundledStrings = null;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
if (position == srcEnd) {
|
|
@@ -933,18 +934,23 @@ currentExtensions[PACKED_REFERENCE_TAG_ID] = (data) => { // packed reference
|
|
|
933
934
|
return packedValues[16 + (data >= 0 ? 2 * data : (-2 * data - 1))]
|
|
934
935
|
throw new Error('No support for non-integer packed references yet')
|
|
935
936
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
937
|
+
|
|
938
|
+
// The following code is an incomplete implementation of http://cbor.schmorp.de/stringref
|
|
939
|
+
// the real thing would need to implemennt more logic to populate the stringRefs table and
|
|
940
|
+
// maintain a stack of stringRef "namespaces".
|
|
941
|
+
//
|
|
942
|
+
// currentExtensions[25] = (id) => {
|
|
943
|
+
// return stringRefs[id]
|
|
944
|
+
// }
|
|
945
|
+
// currentExtensions[256] = (read) => {
|
|
946
|
+
// stringRefs = []
|
|
947
|
+
// try {
|
|
948
|
+
// return read()
|
|
949
|
+
// } finally {
|
|
950
|
+
// stringRefs = null
|
|
951
|
+
// }
|
|
952
|
+
// }
|
|
953
|
+
// currentExtensions[256].handlesRead = true
|
|
948
954
|
|
|
949
955
|
currentExtensions[28] = (read) => {
|
|
950
956
|
// shareable http://cbor.schmorp.de/value-sharing (for structured clones)
|