-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception: Data read but end of buffer not reached #21
Comments
This generally means that the input data is not valid. You created a valid CBOR binary to pass into decode? Here is an example of how you would create a (valid) CBOR encoding using
Do you have a sample of your code that is failing? |
I definitely was not doing this. So let me explain what I am trying to do here. I am working with a crypto wallet and it gives me a 124 char hex encoded cbor string. I need to decode that string so parts of it can be used for validation. So I tried to convert it to a Uint8Array as your decode method didnt work with a string. This is not sensitive info, just FYI. |
You would need to first convert the hex string to binary bytes (there are lot of different types of string/binary encodings). If you are working in NodeJS you could just decode the hex string to a buffer by specifying it as the string encoding:
If you are not working Node, there are plenty of examples of how to convert a hex to a Uint8Array like:
I don't really know what the returned CBOR structure means, but I assume it means something to you. |
So what I am getting back is I need code to do something like what happens on cbor.me. Thanks in advance. |
Your CBOR structure is a map where the keys are binary data. This doesn't really have a clear JS equivalent, because JS requires that object keys be strings (or symbols or numbers), not typed arrays (like Uint8Array). So in the browser, if you are using the default setting where maps are mapped to objects, the typed array just gets coerced to a string ("0,185,105,41,195,...").
I have no idea, this is the binary data for the key that came from your data. It is the decimal representation of that binary data (and 00B96929C38EF48... is the hexadecimal representation of that same binary data). If you want to preserve the original keys, you may want to consider mapping the CBOR map structures to JS Maps, which will preserve the original binary data:
|
Thanks a million. You are the best! Thank you for your patience, kindness and absolute brilliance. Needless to say your very quick responses. My hats off to you. As you can probably tell I am not a JS expert but I am also in the middle of a ton of things so I greatly appreciate all your help. |
I am trying to decode a cbor string. I used TextEncoder to convert it to Uint8Array and used the decode function when I get this error.
index.js:138 Uncaught (in promise) Error: Data read, but end of buffer not reached
at checkedRead (index.js:138)
at Object.decode (index.js:86)
Please help.
The text was updated successfully, but these errors were encountered: