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 Attachments = require('../../app/attachments');
const {
stringToArrayBuffer,
} = require('../../js/modules/string_to_array_buffer');
const { stringToArrayBuffer } = require('../../ts/util/stringToArrayBuffer');
const PREFIX_LENGTH = 2;
const NUM_SEPARATORS = 1;

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,8 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { stringToArrayBuffer } from '../util/stringToArrayBuffer';
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
/* 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}`);
}
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
const utils = {
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
exports.stringToArrayBuffer = string => {
export function stringToArrayBuffer(string: string): ArrayBuffer {
if (typeof string !== 'string') {
throw new TypeError("'string' must be a string");
}
@ -11,4 +11,4 @@ exports.stringToArrayBuffer = string => {
array[i] = string.charCodeAt(i);
}
return array.buffer;
};
}