Skip to content

Commit 9748923

Browse files
committed
Merge pull request #390 from uProxy/trevj-arraybuffers-unused
remove unused ArrayBuffer <-> UTF8 string converters
2 parents 3a29601 + 2bd9668 commit 9748923

File tree

2 files changed

+0
-65
lines changed

2 files changed

+0
-65
lines changed

src/arraybuffers/arraybuffers.spec.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ var array2 = uint8Array2.buffer;
1212
var string2 = '\x00\x02\x81\x80\x00\x01\x00\x05\x00';
1313
var hexString2 = '0.2.81.80.0.1.0.5.0';
1414

15-
var uint8Array3 = new Uint8Array(
16-
[0xE5, 0xA4, 0xA7, 0xE7, 0xBA, 0xAA, 0xE5, 0x85, 0x83]);
17-
var array3 = uint8Array3.buffer;
18-
var string3 = '大纪元';
19-
2015
var uint8Array12 = new Uint8Array(
2116
[12,118,101,114,105,115,0,2,129,128,0,1,0,5,0]);
2217
var array12 = uint8Array12.buffer;
@@ -142,36 +137,3 @@ describe('ArrayBuffers <-> strings', function() {
142137
.not.toEqual(string2);
143138
});
144139
});
145-
146-
describe('ArrayBuffers(UTF8) <-> strings', function() {
147-
it('Empty Buffer -> Empty String', function() {
148-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(emptyArray)).toEqual(emptyString);
149-
});
150-
it('Empty String -> Empty Buffer', function() {
151-
expect(arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString).byteLength).toEqual(0);
152-
});
153-
154-
it('Buffer(UTF8) -> String', function() {
155-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(emptyArray)).toEqual(emptyString);
156-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(array1)).toEqual(string1);
157-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(array3)).toEqual(string3);
158-
});
159-
160-
it('String -> Buffer(UTF8)', function() {
161-
expect(arraybuffers.byteEquality(
162-
arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString), emptyArray)).toBe(true);
163-
expect(arraybuffers.byteEquality(
164-
arraybuffers.stringToUtf8EncodedArrayBuffer(string1), array1)).toBe(true);
165-
expect(arraybuffers.byteEquality(
166-
arraybuffers.stringToUtf8EncodedArrayBuffer(string3), array3)).toBe(true);
167-
});
168-
169-
it('String -> Buffer(UTF8) -> String = identity', function() {
170-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
171-
arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString))).toEqual(emptyString);
172-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
173-
arraybuffers.stringToUtf8EncodedArrayBuffer(string1))).toEqual(string1);
174-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
175-
arraybuffers.stringToUtf8EncodedArrayBuffer(string3))).toEqual(string3);
176-
});
177-
});

src/arraybuffers/arraybuffers.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ export function stringToArrayBuffer(s:string) :ArrayBuffer {
7070
return buffer;
7171
}
7272

73-
// Escape and unescape are actually globally defined functions.
74-
declare function escape(s:string):string;
75-
declare function unescape(s:string):string;
76-
7773
// Converts an ArrayBuffer to a string of hex codes (of the regexp form
7874
// /(hh\.)*hh/).
7975
export function arrayBufferToHexString(buffer:ArrayBuffer) :string {
@@ -98,29 +94,6 @@ export function hexStringToArrayBuffer(hexString:string) :ArrayBuffer {
9894
return buffer;
9995
}
10096

101-
// Converts arrayBuffer which has a string encoded in UTF8 to a
102-
// Javascript string.
103-
//
104-
// Note: the array buffer should have a valid string with no zero inside.
105-
export function arrayBufferDecodedAsUtf8String(buffer:ArrayBuffer) :string {
106-
var bytes = new Uint8Array(buffer);
107-
var a :string[] = [];
108-
for (var i = 0; i < bytes.length; ++i) {
109-
a.push(String.fromCharCode(bytes[i]));
110-
}
111-
return decodeURIComponent(escape(a.join('')));
112-
}
113-
114-
// Converts javascript string to array buffer using UTF8 encoding.
115-
export function stringToUtf8EncodedArrayBuffer(str:string) :ArrayBuffer {
116-
var strUtf8 = unescape(encodeURIComponent(str));
117-
var ab = new Uint8Array(strUtf8.length);
118-
for (var i = 0; i < strUtf8.length; i++) {
119-
ab[i] = strUtf8.charCodeAt(i);
120-
}
121-
return ab.buffer;
122-
}
123-
12497
// Returns an ArrayBuffer backed by the same memory as the supplied
12598
// Node.js Buffer.
12699
export function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer {

0 commit comments

Comments
 (0)