2018-04-27 21:25:04 +00:00
|
|
|
exports.stringToArrayBuffer = string => {
|
2018-03-23 19:49:08 +00:00
|
|
|
if (typeof string !== 'string') {
|
2018-04-11 19:44:52 +00:00
|
|
|
throw new TypeError("'string' must be a string");
|
2018-03-23 19:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const array = new Uint8Array(string.length);
|
|
|
|
for (let i = 0; i < string.length; i += 1) {
|
|
|
|
array[i] = string.charCodeAt(i);
|
|
|
|
}
|
|
|
|
return array.buffer;
|
|
|
|
};
|