Skip to content

Commit 9a9a8e3

Browse files
committed
Merge branch 'master' into trevj-arraybuffers-use-buffer-where-possible
2 parents 922cf18 + 9748923 commit 9a9a8e3

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;
@@ -106,36 +101,3 @@ describe('ArrayBuffers <-> strings', function() {
106101
.not.toEqual(string2);
107102
});
108103
});
109-
110-
describe('ArrayBuffers(UTF8) <-> strings', function() {
111-
it('Empty Buffer -> Empty String', function() {
112-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(emptyArray)).toEqual(emptyString);
113-
});
114-
it('Empty String -> Empty Buffer', function() {
115-
expect(arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString).byteLength).toEqual(0);
116-
});
117-
118-
it('Buffer(UTF8) -> String', function() {
119-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(emptyArray)).toEqual(emptyString);
120-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(array1)).toEqual(string1);
121-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(array3)).toEqual(string3);
122-
});
123-
124-
it('String -> Buffer(UTF8)', function() {
125-
expect(arraybuffers.byteEquality(
126-
arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString), emptyArray)).toBe(true);
127-
expect(arraybuffers.byteEquality(
128-
arraybuffers.stringToUtf8EncodedArrayBuffer(string1), array1)).toBe(true);
129-
expect(arraybuffers.byteEquality(
130-
arraybuffers.stringToUtf8EncodedArrayBuffer(string3), array3)).toBe(true);
131-
});
132-
133-
it('String -> Buffer(UTF8) -> String = identity', function() {
134-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
135-
arraybuffers.stringToUtf8EncodedArrayBuffer(emptyString))).toEqual(emptyString);
136-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
137-
arraybuffers.stringToUtf8EncodedArrayBuffer(string1))).toEqual(string1);
138-
expect(arraybuffers.arrayBufferDecodedAsUtf8String(
139-
arraybuffers.stringToUtf8EncodedArrayBuffer(string3))).toEqual(string3);
140-
});
141-
});

src/arraybuffers/arraybuffers.ts

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

56-
// Escape and unescape are actually globally defined functions.
57-
declare function escape(s:string):string;
58-
declare function unescape(s:string):string;
59-
6056
// Converts an ArrayBuffer to a string of hex codes (of the regexp form
6157
// /(hh\.)*hh/).
6258
export function arrayBufferToHexString(buffer:ArrayBuffer) :string {
@@ -81,29 +77,6 @@ export function hexStringToArrayBuffer(hexString:string) :ArrayBuffer {
8177
return buffer;
8278
}
8379

84-
// Converts arrayBuffer which has a string encoded in UTF8 to a
85-
// Javascript string.
86-
//
87-
// Note: the array buffer should have a valid string with no zero inside.
88-
export function arrayBufferDecodedAsUtf8String(buffer:ArrayBuffer) :string {
89-
var bytes = new Uint8Array(buffer);
90-
var a :string[] = [];
91-
for (var i = 0; i < bytes.length; ++i) {
92-
a.push(String.fromCharCode(bytes[i]));
93-
}
94-
return decodeURIComponent(escape(a.join('')));
95-
}
96-
97-
// Converts javascript string to array buffer using UTF8 encoding.
98-
export function stringToUtf8EncodedArrayBuffer(str:string) :ArrayBuffer {
99-
var strUtf8 = unescape(encodeURIComponent(str));
100-
var ab = new Uint8Array(strUtf8.length);
101-
for (var i = 0; i < strUtf8.length; i++) {
102-
ab[i] = strUtf8.charCodeAt(i);
103-
}
104-
return ab.buffer;
105-
}
106-
10780
// Returns an ArrayBuffer backed by the same memory as the supplied
10881
// Node.js Buffer.
10982
export function bufferToArrayBuffer(buffer: Buffer): ArrayBuffer {

0 commit comments

Comments
 (0)