Actually there's no need to eval/stringify it at all.
atob/btoa will do exactly what you want... Just convert your raw data into a string on the PC (String.fromCharCode.apply(null, data)), and stick it through btoa.
Then to decode, call atob - it'll give you a string, but you can convert that straight to a Uint8Array with: E.toUint8Array(atob(encoded_data))
You might be able to do a little better (avoiding the new allocation for toUint8Array) but hopefully that'll be good enough for you. If you do it right you can make sure that encoded_data gets freed after atob but before toUint8Array
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Actually there's no need to eval/stringify it at all.
atob
/btoa
will do exactly what you want... Just convert your raw data into a string on the PC (String.fromCharCode.apply(null, data)
), and stick it throughbtoa
.Then to decode, call
atob
- it'll give you a string, but you can convert that straight to a Uint8Array with:E.toUint8Array(atob(encoded_data))
You might be able to do a little better (avoiding the new allocation for toUint8Array) but hopefully that'll be good enough for you. If you do it right you can make sure that
encoded_data
gets freed after atob but before toUint8Array