signal-desktop/js/modules/string_to_array_buffer.js
2018-03-26 16:38:34 -04:00

11 lines
300 B
JavaScript

exports.stringToArrayBuffer = (string) => {
if (typeof string !== 'string') {
throw new TypeError('"string" must be a string');
}
const array = new Uint8Array(string.length);
for (let i = 0; i < string.length; i += 1) {
array[i] = string.charCodeAt(i);
}
return array.buffer;
};