首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome FileSystem API中的QUOTA_EXCEEDED_ERR

Chrome FileSystem API中的QUOTA_EXCEEDED_ERR
EN

Stack Overflow用户
提问于 2012-11-20 21:19:15
回答 1查看 5.1K关注 0票数 3

在Chrome23/MacOS10.8.2中,this fiddle记录了一个错误,我想知道为什么。

令人惊讶的是,如果我在显示'// BREAKPOINT‘的行上放置一个断点并简单地继续执行,就不会发生错误。

JS会不会超出Chrome中的某个调用速率限制?我想不出更好的解释了。

完整代码(我使用的是lodash,请参阅其_.bind and _.bindAll文档):

代码语言:javascript
复制
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.LocalFileSystem = window.LocalFileSystem || {PERSISTENT: window.PERSISTENT};

fs = {
 initFS: function() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT,
                             1024 * 1024, this.gotFS, this.fail);
 },

 fail: function(source, err) {
    err.source = source;
    var msg = '';

    switch (err.code) {
      case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
      case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
      case FileError.SECURITY_ERR:
        msg = 'SECURITY_ERR';
        break;
      case FileError.INVALID_MODIFICATION_ERR:
        msg = 'INVALID_MODIFICATION_ERR';
        break;
      case FileError.INVALID_STATE_ERR:
        msg = 'INVALID_STATE_ERR';
        break;
      default:
        msg = 'Unknown Error';
        break;
    };
    err.msg = msg;
    console.log('err ', JSON.stringify(err));
 },
 failarg: function(msg) {
    return _.bind(this.fail, this, msg);
 },

 gotFS: function(fs) {
    this.fs = this.fs || fs;
    this.readConfig();
    this.listApps(fs.root);  // BREAKPOINT
 },

 listApps: function(fsroot) {
    this.rootReader = this.rootReader || fsroot.createReader();
    this.rootReader.readEntries(this.gotRootEntries, this.fail);
 },

 gotRootEntries: function(entries) {
    _(entries).forEach(function(entry) {
        if (entry.isDirectory && this.controller) {
            // TODO
        }
    });
 },

 readConfig: function() {
    this.fs.root.getFile('config.json', {create:true}, this.gotConfigFileEntry, this.failarg('getFile'));
},
gotConfigFileEntry: function(entry) {
    entry.file(this.gotConfigFile, this.failarg('entry.file'));
},
gotConfigFile: function(file) {
    this.configFile = file;

    var reader = new FileReader();
    reader.onloaded = function(evt) {
        if (evt.target.result) {
            this.config = JSON.parse(evt.target.result);
        }
    };
    reader.readAsText(this.configFile);
},
};
_.bindAll(fs);

$(function() {
   fs.initFS();
});​
EN

回答 1

Stack Overflow用户

发布于 2013-05-29 22:20:54

下面这篇基于原始HTML5Rocks文章(http://www.html5rocks.com/en/tutorials/file/filesystem/)的小节演示了如何调用配额系统。

http://jsfiddle.net/kim3er/h76qq/1/

代码语言:javascript
复制
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
  //window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
  initFS(grantedBytes);
}, function(e) {
  console.log('Error', e);
});
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13474089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档