3

webkitStorageInfo.queryUsageAndQuota() 用于查找已使用 HTML5 文件系统 API 存储在文件系统中的文件的使用情况统计信息。谁能给我在提供给此函数的回调中可以获得的详细信息。

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

3 回答 3

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);  }
);

请求配额

var requestedBytes = 1024*1024*280; 

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

    }, function(e) { console.log('Error', e); }
);

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

当前的 Chrome 实现跟踪这个特定的规范版本,它描述了更多内容:https ://www.w3.org/TR/quota-api/ 。

temporary他们还特别解释了与permanent 此处的区别:临时数据更像是您的tmp文件夹或弱引用,因为系统可能会随心所欲地删除内容,而永久数据应始终在删除之前通知用户。

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

chromestore.js是另一个包装器(但多年未触及)。

于 2015-04-15T23:50:19.470 回答
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

回调的解释在这里找到:

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); 
  ...
[NoInterfaceObject, Callback=FunctionOnly]
接口 StorageInfoUsageCallback {
  无效句柄事件(符号长长电流使用字节, 
                   无符号长长电流配额);
};

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

于 2012-05-07T08:09:52.517 回答
2
// Request storage usage and capacity left
window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, //the type can be either TEMPORARY or PERSISTENT
function(used, remaining) {
  console.log("Used quota: " + used + ", remaining quota: " + remaining);
}, function(e) {
  console.log('Error', e); 
} );

使用和剩余的位置以字节为单位

取自谷歌开发者

于 2013-02-01T02:48:51.663 回答