Skip to content

Commit aa36c95

Browse files
committed
Merge pull request #1 from skrat/fixing_encode
Fixing encode
2 parents 1f99cb4 + 45907f1 commit aa36c95

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
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+/");

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "base64-arraybuffer",
33
"description": "Encode/decode base64 data into ArrayBuffers",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"homepage": "https://github.com/niklasvh/base64-arraybuffer",
66
"author": {
77
"name": "Niklas von Hertzen",
@@ -32,4 +32,4 @@
3232
"grunt": "~0.3.17"
3333
},
3434
"keywords": []
35-
}
35+
}

0 commit comments

Comments
 (0)