有什么细节可以从webkitStorageInfo.queryUsageAndQuota()获得

Jop*_*eph 3 html5 google-chrome google-chrome-extension fileapi html5-filesystem

webkitStorageInfo.queryUsageAndQuota()用于查找使用我认为的HTML5文件系统API存储在文件系统中的文件的使用情况统计信息.任何人都可以给我提供可以在提供给该函数的回调中获得的详细信息.

window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.PERSISTENT, function() {
   //what all details can be obtained in this function as its arguments?
})
Run Code Online (Sandbox Code Playgroud)

Pau*_*ish 11

以下是当前 API的两个示例.

它使用navigator.webkitPersistentStorage.requestQuota而不是弃用window.webkitStorageInfo.queryUsageAndQuota:

查询配额

navigator.webkitPersistentStorage.queryUsageAndQuota ( 
    function(usedBytes, grantedBytes) {  
        console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
    }, 
    function(e) { console.log('Error', e);  }
);
Run Code Online (Sandbox Code Playgroud)

请求配额

var requestedBytes = 1024*1024*280; 

navigator.webkitPersistentStorage.requestQuota (
    requestedBytes, function(grantedBytes) {  
        console.log('we were granted ', grantedBytes, 'bytes');

    }, function(e) { console.log('Error', e); }
);
Run Code Online (Sandbox Code Playgroud)

这里我们navigator.webkitPersistentStorage用来查询和请求持久存储配额.您还可以使用navigator.webkitTemporaryStorage与工作临时存储配额.

目前的Chrome实施跟踪了这个特定的规范版本,它更详细地描述了一些内容:https://www.w3.org/TR/quota-api/.

他们还具体解释了这里temporary和之间的区别:临时数据更像是你的文件夹或弱引用,因为,系统可能会删除事物,而永久数据应该在被删除之前通知用户.permanent tmp

您可能希望从包装器开始,以逃避与Web API相关的所有浏览器兼容性问题(规范的许多部分明确指出:"这是一个提议,可能会在没有任何通知的情况下进行更改").例如,Dexie是一个积极开发的IndexedDb包装器.

chromestore.js是另一个包装器(但多年来没有被触及).

  • 插件为https://github.com/ebidel/filer.js,它是Filesystem API之上的另一个帮助程序,并使用更新的配额API. (2认同)

Rob*_*b W 5

替换function(){...}console.log.bind(console),你就会发现。

> window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.PERSISTENT, console.log.bind(console))
undefined  // Return value of ^
0 0        // Printed results, argument 0 and argument 1
Run Code Online (Sandbox Code Playgroud)

回调的解释可以在这里找到:

interface StorageInfo { 
  ....
  // Queries the current quota and how much data is stored for the host. 
  void queryUsageAndQuota( 
      unsigned short storageType, 
      optional StorageInfoUsageCallback successCallback, 
      optional StorageInfoErrorCallback errorCallback); 
  ...
Run Code Online (Sandbox Code Playgroud)
[NoInterfaceObject,Callback=FunctionOnly] 
接口 StorageInfoUsageCallback { 
  void handleEvent( unsigned long long currentUsageInBytes , 
                    unsigned long long currentQuotaInBytes );
};

因此,第一个数字表示使用了多少字节,
第二个数字表示配额的大小。