Socket
Socket
Sign inDemoInstall

base64-js

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base64-js - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

LICENSE.MIT

40

lib/b64.js

@@ -7,23 +7,13 @@ (function (exports) {

function b64ToByteArray(b64) {
var i, j, l, tmp, placeHolders, arr;
if (b64.length % 4 > 0) {
var i, l, tmp, hasPadding, arr = [];
if (i % 4 > 0) {
throw 'Invalid string. Length must be a multiple of 4';
}
// the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
placeHolders = b64.indexOf('=');
placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
hasPadding = /=$/.test(b64);
// base64 is 4/3 + up to two characters of the original data
arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
l = hasPadding ? b64.length - 4: b64.length;
// if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? b64.length - 4 : b64.length;
for (i = 0, j = 0; i < l; i += 4, j += 3) {
for (i = 0; i < l; i += 4) {
tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);

@@ -35,9 +25,13 @@ arr.push((tmp & 0xFF0000) >> 16);

if (placeHolders === 2) {
tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
arr.push(tmp & 0xFF);
} else if (placeHolders === 1) {
tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
arr.push((tmp >> 8) & 0xFF);
arr.push(tmp & 0xFF);
if (hasPadding) {
b64 = b64.substring(i, b64.indexOf('='));
if (b64.length === 2) {
tmp = (lookup.indexOf(b64[0]) << 2) | (lookup.indexOf(b64[1]) >> 4);
arr.push(tmp & 0xFF);
} else {
tmp = (lookup.indexOf(b64[0]) << 10) | (lookup.indexOf(b64[1]) << 4) | (lookup.indexOf(b64[2]) >> 2);
arr.push((tmp >> 8) & 0xFF);
arr.push(tmp & 0xFF);
}
}

@@ -44,0 +38,0 @@

@@ -5,6 +5,6 @@ {

"description": "Base64 encoding/decoding in pure JS",
"version": "0.0.2",
"version": "0.0.3",
"repository": {
"type": "git",
"url": "git://github.com/beatgammit/deflate-js.git"
"url": "git://github.com/beatgammit/base64-js.git"
},

@@ -18,4 +18,5 @@ "main": "lib/b64.js",

},
"license": "MIT",
"dependencies": {},
"devDependencies": {}
}

@@ -21,19 +21,8 @@ (function () {

arr,
arr2,
str,
i,
l;
str;
arr2 = [];
for (i = 0, l = check.length; i < l; i += 1) {
arr2.push(check.charCodeAt(i));
}
b64Str = b64.fromByteArray(arr2);
b64Str = b64.fromByteArray(Array.prototype.map.call(check, function (char) { return char.charCodeAt(0); }));
arr = b64.toByteArray(b64Str);
arr2 = [];
for (i = 0, l = arr.length; i < l; i += 1) {
arr2.push(String.fromCharCode(arr[i]));
}
str = arr2.join('');
str = arr.map(function (byte) { return String.fromCharCode(byte); }).join('');
if (check !== str) {

@@ -40,0 +29,0 @@ console.log('Fail:', check);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc