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

@ -1,4 +0,0 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function stringToArrayBuffer(string: string): ArrayBuffer;

View file

@ -9,9 +9,7 @@ const { assert } = require('chai');
const { app } = require('electron'); const { app } = require('electron');
const Attachments = require('../../app/attachments'); const Attachments = require('../../app/attachments');
const { const { stringToArrayBuffer } = require('../../ts/util/stringToArrayBuffer');
stringToArrayBuffer,
} = require('../../js/modules/string_to_array_buffer');
const PREFIX_LENGTH = 2; const PREFIX_LENGTH = 2;
const NUM_SEPARATORS = 1; const NUM_SEPARATORS = 1;

View file

@ -5,9 +5,7 @@ const { assert } = require('chai');
const sinon = require('sinon'); const sinon = require('sinon');
const Contact = require('../../../js/modules/types/contact'); const Contact = require('../../../js/modules/types/contact');
const { const { stringToArrayBuffer } = require('../../../ts/util/stringToArrayBuffer');
stringToArrayBuffer,
} = require('../../../js/modules/string_to_array_buffer');
describe('Contact', () => { describe('Contact', () => {
const NUMBER = '+12025550099'; const NUMBER = '+12025550099';

View file

@ -6,9 +6,7 @@ const sinon = require('sinon');
const Message = require('../../../js/modules/types/message'); const Message = require('../../../js/modules/types/message');
const { SignalService } = require('../../../ts/protobuf'); const { SignalService } = require('../../../ts/protobuf');
const { const { stringToArrayBuffer } = require('../../../ts/util/stringToArrayBuffer');
stringToArrayBuffer,
} = require('../../../js/modules/string_to_array_buffer');
describe('Message', () => { describe('Message', () => {
const logger = { const logger = {

View file

@ -6,7 +6,7 @@ import { assert } from 'chai';
import * as Attachment from '../../types/Attachment'; import * as Attachment from '../../types/Attachment';
import * as MIME from '../../types/MIME'; import * as MIME from '../../types/MIME';
import { SignalService } from '../../protobuf'; import { SignalService } from '../../protobuf';
import { stringToArrayBuffer } from '../../../js/modules/string_to_array_buffer'; import { stringToArrayBuffer } from '../../util/stringToArrayBuffer';
import * as logger from '../../logging/log'; import * as logger from '../../logging/log';
describe('Attachment', () => { describe('Attachment', () => {

View file

@ -7,7 +7,7 @@ import * as Message from '../../../types/message/initializeAttachmentMetadata';
import { IncomingMessage } from '../../../types/Message'; import { IncomingMessage } from '../../../types/Message';
import { SignalService } from '../../../protobuf'; import { SignalService } from '../../../protobuf';
import * as MIME from '../../../types/MIME'; import * as MIME from '../../../types/MIME';
import { stringToArrayBuffer } from '../../../../js/modules/string_to_array_buffer'; import { stringToArrayBuffer } from '../../../util/stringToArrayBuffer';
describe('Message', () => { describe('Message', () => {
describe('initializeAttachmentMetadata', () => { describe('initializeAttachmentMetadata', () => {

View file

@ -1,6 +1,8 @@
// Copyright 2020 Signal Messenger, LLC // Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import { stringToArrayBuffer } from '../util/stringToArrayBuffer';
/* eslint-disable guard-for-in */ /* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-restricted-syntax */
/* eslint-disable no-proto */ /* eslint-disable no-proto */
@ -62,18 +64,6 @@ function ensureStringed(thing: any): any {
throw new Error(`unsure of how to jsonify object of type ${typeof thing}`); throw new Error(`unsure of how to jsonify object of type ${typeof thing}`);
} }
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;
}
// Number formatting utils // Number formatting utils
const utils = { const utils = {
getString, getString,

View file

@ -1,7 +1,7 @@
// Copyright 2018-2020 Signal Messenger, LLC // Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
exports.stringToArrayBuffer = string => { export function stringToArrayBuffer(string: string): ArrayBuffer {
if (typeof string !== 'string') { if (typeof string !== 'string') {
throw new TypeError("'string' must be a string"); throw new TypeError("'string' must be a string");
} }
@ -11,4 +11,4 @@ exports.stringToArrayBuffer = string => {
array[i] = string.charCodeAt(i); array[i] = string.charCodeAt(i);
} }
return array.buffer; return array.buffer;
}; }