2018-03-23 19:49:08 +00:00
|
|
|
exports.stringToArrayBuffer = (string) => {
|
|
|
|
if (typeof string !== 'string') {
|
2018-03-23 22:24:50 +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;
|
|
|
|
};
|