-
-
Notifications
You must be signed in to change notification settings - Fork 71
Closed
Description
The doc for decodeFirst says, my emphasis:
Decode the first CBOR item in the input. This will error if there are more bytes left over at the end
Several things are confusing me.
- I specifically want to interpret data which consists of CBOR items interleaved with other binary items. I was hoping node-cbor could read the first whole CBOR item and then return control to my code, either consuming the CBOR item from something like a stream or returning the offset of the first byte after the first CBOR item. My code would then, after reading the CBOR item, decide whether to read another CBOR item or to do something else with the remaining binary. Is this possible with node-cbor?
- It doesn't make sense to me why a "decodeFirst" function would have a requirement that it consume its entire input. That sounds more like a "decodeOne" sort of operation.
- The "This will error if there are more bytes left over at the end" language is present in the docs for "decodeFirst", but not for "decodeFirstSync". Is one of the two function docs in error?
- Despite this, eyeballing the source code, I'm not sure I understand it but it looks (?) like there is a specific check for additional data at the end for decodeFirstSync, but I don't see such a check at the end of decodeFirst.
Given all this, my questions:
- Is the documentation for decodeFirst and decodeFirstSync both accurate?
- How do I consume the first CBOR item in a stream/arraybuffer while leaving the remaining bytes for future operations?
Metadata
Metadata
Assignees
Labels
No labels