[Suggestion] Add base64 built in
Soapy7261 opened this issue ยท 5 comments
Useful information to include:
- A function like
textutils.base64.encode(stringofbinaryornonbinarydatahere)
, or like how python has it with thebase64
package havingb64encode
/b64decode
along withb32encode
/b32decode
under the samebase64
package - Things like web socket sending require encoding binary data as Base64, there are LUA packages that do this, but they are quite slow for large amounts of binary data, it would be nice if it was included (using a java implementation ideally so it could be done faster), other bases (like base32) would be nice too.
- I have considered using
textutils.urlEncode()
, and it does work for smaller strings of binary data, but it has a bug(?) where if the string is too big, it never yields so you get the dreaded 'Too long without yielding' error, even if that was fixed it would still be nice to have base64 built in.
Things like web socket sending require encoding binary data as Base64
Not sure if you're aware but websockets should support sending binary messages.
I have considered using
textutils.urlEncode()
, but it has a bug(?) where if the string is too big, it never yields. [...] There are LUA packages that do this, but they are quite slow for large amounts of binary data, it would be nice if it was included (using a java implementation ideally so it could be done faster)
textutils.urlEncode
is probably not the right tool here, but I am curious how much data you're trying to send here? Looking at the implementation, there's some obvious optimisations there which I'll make, but it should be fine for anything less than a megabyte.
I generally prefer putting this stuff in Lua where possible, so would like to understand what performance expectations you have.
Not sure if you're aware but websockets should support sending binary messages.
Well, I guess there goes 3 hours of my life I'll never get back.
textutils.urlEncode is probably not the right tool here, but I am curious how much data you're trying to send here? Looking at the implementation, there's some obvious optimisations there which I'll make, but it should be fine for anything less than a megabyte.
I'll admit I was trying to encode a 150MB file, but the limit before that happens is probably quite a bit lower, I'll do more testing when I have more time
I generally prefer putting this stuff in Lua where possible, so would like to understand what performance expectations you have.
That's understandable, even if it was in LUA, it would still be nice to have included