How can I urlencode a UInt8Array in JavaScript? using encodeURIComponent does not work, for example with
encodeURIComponent((new Uint8Array([72,101,108,108,111,32,87,111,114,108,100])));
I expected:
Hello%20World
but I got
72%2C101%2C108%2C108%2C111%2C32%2C87%2C111%2C114%2C108%2C100"
Don't know of any native function to do it, wrote a custom encoder, it should be binary-safe:
and doing
gives the expected
... However testing shows that a lookup table is much faster:
urlencode() use about 2000 milliseconds on 10MB, and urlencode2() use about 800 milliseconds on 10MB, a lookup table more-than-doubles the performance on Edge!
And on Firefox the results are even better (in all cases, for some reason..) urlencode() use about 500 milliseconds and urlencode2() use about 61 milliseconds, a lookup table is 8 times faster on Firefox!
.. I guess function call overhead is to blame?