Skip to content

Commit 9b56b6a

Browse files
committed
Fix unpackaging older base 85 on big endian systems
1 parent bcbd121 commit 9b56b6a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

unpackager.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ var unpackage = (function() {
7979
const lengthEndsAt = str.indexOf(',');
8080
const byteLength = +str.substring(0, lengthEndsAt);
8181
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
82-
const resultView = new Uint32Array(resultBuffer);
82+
const resultView = new DataView(resultBuffer);
8383
const stringBytes = stringToBytes(str);
84-
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
85-
resultView[j] = (
84+
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
85+
resultView.setUint32(j, (
8686
getValue(stringBytes[i + 4]) * 85 * 85 * 85 * 85 +
8787
getValue(stringBytes[i + 3]) * 85 * 85 * 85 +
8888
getValue(stringBytes[i + 2]) * 85 * 85 +
8989
getValue(stringBytes[i + 1]) * 85 +
9090
getValue(stringBytes[i])
91-
);
91+
), true);
9292
}
9393
return new Uint8Array(resultBuffer, 0, byteLength);
9494
};
@@ -113,16 +113,16 @@ var unpackage = (function() {
113113
const lengthEndsAt = str.indexOf(',');
114114
const byteLength = +str.substring(0, lengthEndsAt);
115115
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
116-
const resultView = new Uint32Array(resultBuffer);
116+
const resultView = new DataView(resultBuffer);
117117
const stringBytes = stringToBytes(str);
118-
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
119-
resultView[j] = (
118+
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
119+
resultView.setUint32(j, (
120120
getValue(stringBytes[i + 4]) * 85 * 85 * 85 * 85 +
121121
getValue(stringBytes[i + 3]) * 85 * 85 * 85 +
122122
getValue(stringBytes[i + 2]) * 85 * 85 +
123123
getValue(stringBytes[i + 1]) * 85 +
124124
getValue(stringBytes[i])
125-
);
125+
), true);
126126
}
127127
return new Uint8Array(resultBuffer, 0, byteLength);
128128
};
@@ -148,15 +148,15 @@ var unpackage = (function() {
148148
.map(i => String.fromCharCode(i.charCodeAt(0) - 49))
149149
.join('');
150150
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
151-
const resultView = new Uint32Array(resultBuffer);
152-
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
153-
resultView[j] = (
151+
const resultView = new DataView(resultBuffer);
152+
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
153+
resultView.setUint32(j, (
154154
getValue(str.charCodeAt(i + 4)) * 85 * 85 * 85 * 85 +
155155
getValue(str.charCodeAt(i + 3)) * 85 * 85 * 85 +
156156
getValue(str.charCodeAt(i + 2)) * 85 * 85 +
157157
getValue(str.charCodeAt(i + 1)) * 85 +
158158
getValue(str.charCodeAt(i))
159-
);
159+
), true);
160160
}
161161
return new Uint8Array(resultBuffer, 0, byteLength);
162162
};

0 commit comments

Comments
 (0)