Skip to content

Commit 2583015

Browse files
committed
Fixed encode method bug.
1 parent 2ec6e42 commit 2583015

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/base64-arraybuffer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
exports.encode = function(arraybuffer) {
1212
var bytes = new Uint8Array(arraybuffer),
13-
i, len = bytes.buffer.byteLength, base64 = "";
13+
i, len = bytes.length, base64 = "";
1414

1515
for (i = 0; i < len; i+=3) {
16-
base64 += chars[bytes.buffer[i] >> 2];
17-
base64 += chars[((bytes.buffer[i] & 3) << 4) | (bytes.buffer[i + 1] >> 4)];
18-
base64 += chars[((bytes.buffer[i + 1] & 15) << 2) | (bytes.buffer[i + 2] >> 6)];
19-
base64 += chars[bytes.buffer[i + 2] & 63];
16+
base64 += chars[bytes[i] >> 2];
17+
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
18+
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
19+
base64 += chars[bytes[i + 2] & 63];
2020
}
2121

2222
if ((len % 3) === 2) {
@@ -56,4 +56,4 @@
5656

5757
return arraybuffer;
5858
};
59-
})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
59+
})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");

0 commit comments

Comments
 (0)