[pbs-devel] [PATCH widget-toolkit v4 1/7] utils: add base64 conversion helper

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Nov 26 12:06:24 CET 2024


Am 26.11.24 um 11:31 schrieb Gabriel Goller:
> On 17.09.2024 09:37, Thomas Lamprecht wrote:
>> FWIW this could be a bit shorter by using map (which typed arrays
>> also support [0]):
>>
>>        const escapedString = bytes.map(b => String.fromCodePoint(b)).join('');
>>
>> But for that we really need no new revision.
>>
>> [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map
> 
> I just tried this and it sadly doesn't work. `String.fromCodePoint`
> returns a string, which can't be stored in the `Uint8Array` which is `bytes`.

You are right, sorry for the misdirection.
One would need the non-typed array method for that, i.e.:

var escapedString = Array.prototype.map.call(bytes, b => String.fromCodePoint(b)).join('');

Which really is not nicer than what you did, so let's go with that.




More information about the pbs-devel mailing list