文件系统无法在Ripple Emulator上运行,适用于设备

时间:2014-02-26 18:20:10

标签: debugging google-chrome cordova filesystems ripple

尝试以平稳的方式启动和运行我的调试。我现在可以通过运行我的设备来测试FileSystem API,但这是一个痛苦的过程。我尝试使用我在SO上找到的代码设置Chrome文件系统API。我得到了一个文件系统的返回(虽然它是未命名的“”和fullPath =“/”)。我收到了Chrome应用程序想要在本地存储的请求,我接受了。但每次创建目录都会失败。设备的代码(唯一的区别是对本地文件系统的请求)有效。

有什么想法?我希望能够在转移到设备之前在Ripple中进行调试。

// Chrome dev tools

// Request Quota (only for File System API)

navigator.webkitPersistentStorage.requestQuota(1024*1024, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onFileSystemSuccess, onFileSystemFail); 
}, function(e) {
console.log('Error', e); 
});


// // Non-chrome (device): get local file system

// window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);


function onFileSystemSuccess(fileSystem) {
    console.log(fileSystem.name);
    console.log(fileSystem.root.name);
    var storageDir = fileSystem.root
    console.log(storageDir, storageDir.fullPath);

    // Find or create new STL directory

    function getDirSuccess(dirEntry) {
        console.log("Directory Name: " + dirEntry.name);
        alert("Your files are stored in: " + dirEntry.name);


        // Find or create new templates file.
        //                    test file

          dirEntry.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);

          function gotFileEntry(fileEntry) {
              fileEntry.createWriter(gotFileWriter, fail);
          }

          function gotFileWriter(writer) {
              writer.onwriteend = function(evt) {
                  console.log("contents of file now 'some sample text'");
                  writer.truncate(11);
                  writer.onwriteend = function(evt) {
                      console.log("contents of file now 'some sample'");
                      writer.seek(4);
                      writer.write(" different text");
                      writer.onwriteend = function(evt){
                          console.log("contents of file now 'some different text'");
                      }
                  };
              };
              writer.write("some sample text");
              alert('wrote a text file');
          }

function fail(error) {
    console.log(error.code);
}

0 个答案:

没有答案