From 4fb04b8f5345dd2c20d5ce69b0a4ee91bf5bfacf Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Mon, 16 Sep 2019 12:36:18 -0700 Subject: [PATCH] base64 shim --- package.json | 2 +- sea.js | 17 ++++++++++------- test/sea/sea.js | 3 --- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 7ed4f77a..cee14d76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.2019.910", + "version": "0.2019.915", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "main": "index.js", "browser": "gun.js", diff --git a/sea.js b/sea.js index f0a9725f..ee2fbf8f 100644 --- a/sea.js +++ b/sea.js @@ -17,13 +17,6 @@ } if(typeof module !== "undefined"){ var common = module } /* UNBUILD */ - function atob(a) { - return new Buffer(a, 'base64').toString('binary'); - }; - - function btoa(b) { - return new Buffer(b).toString('base64'); - }; ;USE(function(module){ // Security, Encryption, and Authorization: SEA.js @@ -54,6 +47,15 @@ })(USE, './https'); ;USE(function(module){ + if(typeof global !== "undefined"){ + var g = global; + g.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); }; + g.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); }; + } + })(USE, './base64'); + + ;USE(function(module){ + USE('./base64'); // This is Array extended to have .toString(['utf8'|'hex'|'base64']) function SeaArray() {} Object.assign(SeaArray, { from: Array.from }) @@ -79,6 +81,7 @@ })(USE, './array'); ;USE(function(module){ + USE('./base64'); // This is Buffer implementation used in SEA. Functionality is mostly // compatible with NodeJS 'safe-buffer' and is used for encoding conversions // between binary and 'hex' | 'utf8' | 'base64' diff --git a/test/sea/sea.js b/test/sea/sea.js index bd7f59c2..e4e5f70e 100644 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -1,8 +1,5 @@ var root; var Gun; -function atob(a) { - return new Buffer(a, 'base64').toString('binary'); -}; (function(){ var env; if(typeof global !== 'undefined'){ env = global }