Moves stringToArrayBuffer into util folder

This commit is contained in:
Josh Perez 2021-09-20 12:27:15 -04:00 committed by GitHub
parent 829e42ca6e
commit e86a6119cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 30 deletions

View file

@ -0,0 +1,14 @@
// Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function stringToArrayBuffer(string: string): ArrayBuffer {
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;
}