Skip to content
Browse files

Fixed an oops with trailing bytes

  • Loading branch information...
1 parent 208250b commit 2bf900120907e1319336de7a229514ff2de0dd9f @beatgammit committed Nov 21, 2011
Showing with 10 additions and 14 deletions.
  1. +1 −1 package.json
  2. +9 −13 src/download.js
View
2 package.json
@@ -3,7 +3,7 @@
"name": "toDataURL",
"description": "Download something in the browser as a file",
"keywords": ["dataURL", "download"],
- "version": "0.1.0",
+ "version": "0.1.1",
"repository": {
"type": "git",
"url": "https://github.com/beatgammit/toDataURL.git"
View
22 src/download.js
@@ -28,25 +28,21 @@
output += tripletToBase64(temp);
}
+ // pad the end with zeros, but make sure to not forget the extra bytes
switch (extraBytes) {
case 1:
- output += 'AA';
+ temp = uint8[uint8.length - 1];
+ output += lookup[temp >> 2];
+ output += lookup[(temp << 4) & 0x3F];
+ output += '==';
break;
case 2:
- output += 'A';
- break;
- }
-
- // this prevents an ERR_INVALID_URL in Chrome (Firefox okay)
- switch (output.length % 4) {
- case 1:
+ temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
+ output += lookup[temp >> 10];
+ output += lookup[(temp >> 4) & 0x3F];
+ output += lookup[(temp << 2) & 0x3F];
output += '=';
break;
- case 2:
- output += '==';
- break;
- default:
- break;
}
return output;

0 comments on commit 2bf9001

Please sign in to comment.
Something went wrong with that request. Please try again.