cbor-x 1.6.6 → 1.6.8

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/encode.js CHANGED
@@ -181,7 +181,7 @@ export class Encoder extends Decoder {
181
181
  if (throwOnIterable)
182
182
  return;
183
183
  encode(value)
184
- if (bundledStrings) {
184
+ if (bundledStrings && bundledStrings.position) { // position is only set once a bundle has been started
185
185
  writeBundles(start, encode)
186
186
  }
187
187
  encoder.offset = position // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
package/iterators.js CHANGED
@@ -47,7 +47,7 @@ export function decodeIter (bufferIterator, options = {}) {
47
47
  }
48
48
 
49
49
  const decoder = new Decoder(options)
50
- let incomplete
50
+ let incomplete, fatalError
51
51
  const parser = (chunk) => {
52
52
  let yields
53
53
  // if there's incomplete data from previous chunk, concatinate and try again
@@ -59,26 +59,28 @@ export function decodeIter (bufferIterator, options = {}) {
59
59
  try {
60
60
  yields = decoder.decodeMultiple(chunk)
61
61
  } catch (err) {
62
+ yields = err.values
62
63
  if (err.incomplete) {
63
64
  incomplete = chunk.slice(err.lastPosition)
64
- yields = err.values
65
65
  } else {
66
- throw err
66
+ fatalError = err
67
67
  }
68
68
  }
69
- return yields
69
+ return yields || []
70
70
  }
71
71
 
72
72
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
73
73
  return (function * iter () {
74
74
  for (const value of bufferIterator) {
75
75
  yield * parser(value)
76
+ if (fatalError) throw fatalError
76
77
  }
77
78
  })()
78
79
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
79
80
  return (async function * iter () {
80
81
  for await (const value of bufferIterator) {
81
82
  yield * parser(value)
83
+ if (fatalError) throw fatalError
82
84
  }
83
85
  })()
84
86
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cbor-x",
3
3
  "author": "Kris Zyp",
4
- "version": "1.6.6",
4
+ "version": "1.6.8",
5
5
  "description": "Ultra-fast and conformant CBOR (RFC 8949) implementation with support for numerous tag extensions including records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/stream.js CHANGED
@@ -36,24 +36,22 @@ export class DecoderStream extends Transform {
36
36
  chunk = Buffer.concat([this.incompleteBuffer, chunk])
37
37
  this.incompleteBuffer = null
38
38
  }
39
- let values
39
+ let values, fatalError
40
40
  try {
41
41
  values = this.decoder.decodeMultiple(chunk)
42
42
  } catch(error) {
43
- if (error.incomplete) {
43
+ values = error.values
44
+ if (error.incomplete)
44
45
  this.incompleteBuffer = chunk.slice(error.lastPosition)
45
- values = error.values
46
- } else {
47
- return callback(error)
48
- }
49
- } finally {
50
- for (let value of values || []) {
51
- if (value === null)
52
- value = this.getNullValue()
53
- this.push(value)
54
- }
46
+ else
47
+ fatalError = error
48
+ }
49
+ for (let value of values || []) {
50
+ if (value === null)
51
+ value = this.getNullValue()
52
+ this.push(value)
55
53
  }
56
- callback()
54
+ callback(fatalError)
57
55
  }
58
56
  getNullValue() {
59
57
  return Symbol.for(null)