Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lrusso authored Aug 14, 2020
1 parent 8906f00 commit 04631e1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WebToApp.htm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<input type="button" value="CLICK HERE TO DOWNLOAD A TEXT FILE TO YOUR DEVICE" onclick="downloadTextFile()"/>
<script>
// WebToApp.min.js
class WebToApp{constructor(e,t,a){this.data=e,this.fileName=t,this.mimeType=a,"string"==typeof this.data||this.data instanceof String?this.stringToArrayBuffer(this.data,"UTF-8",this.download):this.download()}download(){try{var e={filename:this.fileName,fileContent:this.arrayBufferToBase64(this.data)};window.webkit.messageHandlers.webToApp.postMessage(e)}catch(e){console.log("WEBTOAPP_FILENAME="+this.fileName);var t=new Blob([this.data],{type:this.mimeType}),a=window.URL.createObjectURL(t);this.download_URL(a)}}download_URL(e){var t;(t=document.createElement("a")).href=e,t.download=this.fileName,document.body.appendChild(t),t.style="display: none",t.click(),t.remove()}arrayBufferToBase64(e){for(var t="",a=new Uint8Array(e),o=a.byteLength,i=0;i<o;i++)t+=String.fromCharCode(a[i]);return window.btoa(t)}stringToArrayBuffer(e,t,a){var o=this,i=new Blob([e],{type:"text/plain;charset="+t}),r=new FileReader;r.onload=function(e){o.download(e.target.result,o.fileName,o.mimeType)},r.readAsArrayBuffer(i)}}
class WebToApp{constructor(e,t,a){this.data=e,this.fileName=t,this.mimeType=a,"string"==typeof this.data||this.data instanceof String?this.stringToArrayBuffer(this.data,"UTF-8",this.download):this.download()}download(){try{var e={filename:this.fileName,fileContent:this.arrayBufferToBase64(this.data)};window.webkit.messageHandlers.webToApp.postMessage(e)}catch(e){console.log("WEBTOAPP_FILENAME="+this.fileName);var t=new Blob([this.data],{type:this.mimeType}),a=window.URL.createObjectURL(t);this.download_URL(a)}}download_URL(e){var t;(t=document.createElement("a")).href=e,t.download=this.fileName,document.body.appendChild(t),t.style="display: none",t.click(),t.remove()}arrayBufferToBase64(e){for(var t="",a=new Uint8Array(e),o=a.byteLength,r=0;r<o;r++)t+=String.fromCharCode(a[r]);return window.btoa(t)}stringToArrayBuffer(e,t,a){var o=this,r=new Blob([e],{type:"text/plain;charset="+t}),i=new FileReader;i.onload=function(e){o.data=e.target.result,o.download()},i.readAsArrayBuffer(r)}}

var myArrayBuffer;
var myFilename;
Expand Down
3 changes: 2 additions & 1 deletion WebToApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class WebToApp
var reader = new FileReader();
reader.onload = function(event)
{
_WebToApp.download(event.target.result, _WebToApp.fileName, _WebToApp.mimeType);
_WebToApp.data = event.target.result;
_WebToApp.download();
};
reader.readAsArrayBuffer(blob);
}
Expand Down
2 changes: 1 addition & 1 deletion WebToApp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04631e1

Please sign in to comment.