In order to tell NetworkManager to create a Wi-Fi access point over D-Bus using Node.js with the node-dbus library I need to provide an SSID as a byte array. As Node.js doesn't have the Blob class from client-side JavaScript my understanding is that I need to use a Buffer for this, but it's not working.
I can successfully turn a byte array into a string with the following code:
let bytes = new Uint8Array(ssidBytes);
let string = new TextDecoder().decode(bytes);
How do I reverse this to get a byte array from a string?
I've tried:
let ssidBytes = Buffer.from(ssid);
And I've tried:
let ssidBytes = [];
for (let i = 0; i < ssid.length; ++i) {
ssidBytes.push(ssid.charCodeAt(i));
}
Assuming there isn't another error in my code (or the library I'm using), neither of these seem to have the desired effect.
For more background information see https://github.com/Shouqun/node-dbus/issues/228 and https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/663
Thanks