I have a set of bytes in an ArrayBuffer. I need to base64 encode this in k6. How do I accomplish this?
In node.js it is data.toString(‘base64’)
in browsers the btoa() function seems to be the way to go.
Neither of these works in k6, or I did not manage to get them to work.
There is the k6 encoding module, which can do encoding.b64encode(string)
But I do not see how to use this on an array of bytes, it seems to only take a string. And what I need to do is to encode an array of bytes.
I tried to encode the string first with String.fromCharCode.apply(null, new Uint8Array(str)) but it does not seem to produce correct result if I encode this with k6.encode.
I also simply tried to do encoding.b64encode(new Uint8Array(typedArray)); but in this case, also the Go implementation throws an error about not being able to convert the Uint8Array to an array of uint8 in Go…
So how to encode byte array to base64 in k6?