• Oh, the File converter does* just that! Creates a heatshrink compressed data you can paste.

    *: There is a bug / typo, so for now (already sent a PR) go there, open the console, and past & run this:

      function fileLoaded() {
        document.getElementById("result").value = "";
        document.getElementById("result").style.­display = "none";
        document.getElementById("size").innerTex­t = "Please Choose a file first";
        if (!bytes) return;
    
        var fileTypeSelect = document.getElementById("fileType");
        var fileType = fileTypeSelect.options[fileTypeSelect.se­lectedIndex].value;
    
        if (bytes.length>(20*1024)) {
          document.getElementById("size").innerTex­t = "File too long - must be less than 20kB";
          return;
        }
    
        var dqStr = "";
        var tmpStr = "";
        var lastCh = 0;
        for (var i=0;i<bytes.length;i++) {
          var ch = bytes[i];
          // templated string
          if (ch==92) tmpStr += "\\\\"; // escaping slash
          else if (ch==96) tmpStr += "\\\`"; // template quote
          else if (lastCh==36 && ch==126) tmpStr += "\\{" // ${
          else tmpStr += String.fromCharCode(ch);
          // double-quoted string
          if (ch==34) dqStr += "\\\"";
          else if (ch==9) dqStr += "\\t";
          else if (ch==10) dqStr += "\\n";
          else if (ch==13) dqStr += "\\r";
          else if (ch==92) dqStr += "\\\\";
          else if (ch>=32 && ch<127)
            dqStr += String.fromCharCode(ch);
          else { // hex code
            if (ch<64 && (i+1>=bytes.length || (bytes[i+1]<48/*0*/ || bytes[i+1]>55/*7*/)))
              dqStr += "\\"+ch.toString(8/*octal*/); // quick compactness hack
            else
              dqStr += "\\x"+(ch+256).toString(16).substr(-2); // hex
          }
          lastCh = ch;
        }
    
        var finalStr = "";
        switch (fileType) {
          case "b64" :
            finalStr = 'atob("'+btoa(String.fromCharCode.apply(­null, bytes))+'")';
            break;
          case "b64c" :
            finalStr = 'E.toString(require("heatshrink").decomp­ress(atob("'+btoa(String.fromCharCode.ap­ply(null, heatshrink.compress(bytes)))+'")))';
            break;
          case "b64b" :
            finalStr = 'var data = new Uint8Array('+bytes.length+');\r\n';
            var BSIZE = 128;
            for (var i=0;i<bytes.length;i+=BSIZE) {
              let d = btoa(String.fromCharCode.apply(null, bytes.slice(i,i+BSIZE)));
              finalStr += 'data.set(atob("'+d+'"),'+i+');\r\n';
            }
            break;
            case "b64f" :
              finalStr = 'var addr=....; // '+bytes.length+' bytes\n';
              var BSIZE = 256;
              for (var i=0;i<bytes.length;i+=BSIZE) {
                let d = btoa(String.fromCharCode.apply(null, bytes.slice(i,i+BSIZE)));
                finalStr += 'require("Flash").write(atob("'+d+'"), addr+'+i+');\r\n';
              }
              break;
          case "quoted" :
            finalStr = '"'+dqStr+'"';
            break;
          case "templated" :
            finalStr = '"'+tmpStr+'"';
            break;
          default: throw new Error("Unknown type!");
        }
        document.getElementById("size").innerTex­t = finalStr.length+" Characters";
        document.getElementById("result").style.­display = "";
        document.getElementById("result").value = finalStr;
      }
    
About

Avatar for AkosLukacs @AkosLukacs started