fix: import buffer into correct global/window

This commit is contained in:
Hadar Rottenberg 2019-11-21 08:29:40 +02:00
parent 325c7b48ed
commit 5172c38913
3 changed files with 13 additions and 14 deletions

14
sea.js
View File

@ -3,9 +3,7 @@
/* UNBUILD */
var root;
if(typeof window !== "undefined"){ root = window }
if(typeof Buffer === "undefined") {
global.Buffer = require("buffer").Buffer
}
if(typeof global !== "undefined"){ root = global }
root = root || {};
var console = root.console || {log: function(){}};
@ -50,10 +48,12 @@
})(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"); };
if(typeof Buffer === "undefined") {
root.Buffer = require("buffer").Buffer
}
if(typeof btoa !== "undefined"){
root.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); };
root.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); };
}
})(USE, './base64');

View File

@ -1,7 +1,9 @@
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"); };
if(typeof Buffer === "undefined") {
root.Buffer = require("buffer").Buffer
}
if(typeof btoa !== "undefined"){
root.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); };
root.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); };
}

View File

@ -6,9 +6,6 @@
if(SEA.window){
api.crypto = window.crypto || window.msCrypto || require('isomorphic-webcrypto');
if(!api.crypto) {
api.crypto = require('isomorphic-webcrypto');
}
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
api.TextEncoder = window.TextEncoder;
api.TextDecoder = window.TextDecoder;