js/core/file.js
// Load a file from the os
Load a file from the os
Load a file from the os
function loadFile(callback, filename, mimeType) {
    if (chrome.fileSystem) {
      chrome.fileSystem.chooseEntry({type: 'openFile', suggestedName:filename}, function(fileEntry) {
        if (!fileEntry) return;
        fileEntry.file(function(file) {
          var reader = new FileReader();
          reader.onload = function(e) {
            var splittedName = fileEntry.name.split(".", 2);
            var newFile = {identifier: "", name: splittedName[0], extension: splittedName[1], content: e.target.result};
            setFilesArray(newFile);
          };
          reader.onerror = function() {
            Espruino.Core.Notifications.error("Error Loading", true);
          };
          reader.readAsText(file);
        });
      });
    } else {
      Espruino.Core.Utils.fileOpenDialog({id:"code",type:"text",mimeType:mimeType}, function(data, mimeType, fileName) {
        callback(convertFromOS(data));
      });
    }
  }
function loadFile ( callback , filename , mimeType ) { if ( chrome . fileSystem ) { chrome . fileSystem . chooseEntry ( { type : 'openFile' , suggestedName : filename } , function ( fileEntry ) { if ( ! fileEntry ) return ; fileEntry . file ( function ( file ) { var reader = new FileReader ( ) ; reader . onload = function ( e ) { var splittedName = fileEntry . name . split ( "." , 2 ) ; var newFile = { identifier : "" , name : splittedName [ 0 ] , extension : splittedName [ 1 ] , content : e . target . result } ; setFilesArray ( newFile ) ; } ; reader . onerror = function ( ) { Espruino . Core . Notifications . error ( "Error Loading" , true ) ; } ; reader . readAsText ( file ) ; } ) ; } ) ; } else { Espruino . Core . Utils . fileOpenDialog ( { id : "code" , type : "text" , mimeType : mimeType } , function ( data , mimeType , fileName ) { callback ( convertFromOS ( data ) ) ; } ) ; } }
Load a file from the os
Load a file from the os
// Chrome Web App / NW.js // Get the name and code of the file and add it to the files array