tweaks to allow `appinfo` to work under node.js

pull/422/head
Gordon Williams 2020-05-14 11:42:10 +01:00
parent 28059d51c4
commit 36009ed212
1 changed files with 4 additions and 1 deletions

View File

@ -1,10 +1,13 @@
if (typeof btoa==="undefined")
function btoa(d) { return Buffer.from(d).toString('base64'); }
// Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)
function toJS(txt) {
var json = JSON.stringify(txt);
var b64 = "atob("+JSON.stringify(btoa(json))+")";
var js = b64.length < json.length ? b64 : json;
if (heatshrink) {
if (typeof heatshrink !== "undefined") {
var ua = new Uint8Array(txt.length);
for (var i=0;i<txt.length;i++) ua[i] = txt.charCodeAt(i);
var c = heatshrink.compress(ua);