signal-desktop/js/modules/string_to_array_buffer.js

12 lines
298 B
JavaScript
Raw Normal View History

2018-04-27 21:25:04 +00:00
exports.stringToArrayBuffer = string => {
if (typeof string !== 'string') {
2018-04-11 19:44:52 +00:00
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;
};