Skip to content

Commit

Permalink
Fix unpackaging older base 85 on big endian systems
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed May 23, 2024
1 parent bcbd121 commit 9b56b6a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions unpackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ var unpackage = (function() {
const lengthEndsAt = str.indexOf(',');
const byteLength = +str.substring(0, lengthEndsAt);
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
const resultView = new Uint32Array(resultBuffer);
const resultView = new DataView(resultBuffer);
const stringBytes = stringToBytes(str);
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
resultView[j] = (
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
resultView.setUint32(j, (
getValue(stringBytes[i + 4]) * 85 * 85 * 85 * 85 +
getValue(stringBytes[i + 3]) * 85 * 85 * 85 +
getValue(stringBytes[i + 2]) * 85 * 85 +
getValue(stringBytes[i + 1]) * 85 +
getValue(stringBytes[i])
);
), true);
}
return new Uint8Array(resultBuffer, 0, byteLength);
};
Expand All @@ -113,16 +113,16 @@ var unpackage = (function() {
const lengthEndsAt = str.indexOf(',');
const byteLength = +str.substring(0, lengthEndsAt);
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
const resultView = new Uint32Array(resultBuffer);
const resultView = new DataView(resultBuffer);
const stringBytes = stringToBytes(str);
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
resultView[j] = (
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
resultView.setUint32(j, (
getValue(stringBytes[i + 4]) * 85 * 85 * 85 * 85 +
getValue(stringBytes[i + 3]) * 85 * 85 * 85 +
getValue(stringBytes[i + 2]) * 85 * 85 +
getValue(stringBytes[i + 1]) * 85 +
getValue(stringBytes[i])
);
), true);
}
return new Uint8Array(resultBuffer, 0, byteLength);
};
Expand All @@ -148,15 +148,15 @@ var unpackage = (function() {
.map(i => String.fromCharCode(i.charCodeAt(0) - 49))
.join('');
const resultBuffer = new ArrayBuffer(toMultipleOfFour(byteLength));
const resultView = new Uint32Array(resultBuffer);
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j++) {
resultView[j] = (
const resultView = new DataView(resultBuffer);
for (let i = lengthEndsAt + 1, j = 0; i < str.length; i += 5, j += 4) {
resultView.setUint32(j, (
getValue(str.charCodeAt(i + 4)) * 85 * 85 * 85 * 85 +
getValue(str.charCodeAt(i + 3)) * 85 * 85 * 85 +
getValue(str.charCodeAt(i + 2)) * 85 * 85 +
getValue(str.charCodeAt(i + 1)) * 85 +
getValue(str.charCodeAt(i))
);
), true);
}
return new Uint8Array(resultBuffer, 0, byteLength);
};
Expand Down

0 comments on commit 9b56b6a

Please sign in to comment.