2015.12.1
请求文件系统
目前只有Chrome 和 Opera支持filesystem
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.TEMPORARY, 1024 * 1024, successCallback, errorCallback);
查询分配和已使用的空间大小
查询永久文件系统大小
navigator.webkitPersistentStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log(‘we are using ‘, usedBytes, ’ of ‘, grantedBytes, ‘bytes’);
},
function(e) { console.log(‘Error’, e.name); }
);
查询临时文件系统大小
navigator.webkitTemporaryStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log(‘we are using ‘, usedBytes, ’ of ‘, grantedBytes, ‘bytes’);
},
function(e) { console.log(‘Error’, e.name); }
);
输出的大小是以字节为单位
查看和清除所有类型的本地存储
1.在地址栏中输入chrome://settings/cookies
2.查看或清除相应网站的文件系统
两种错误
如果在fs.root.getFile(file_path,{create:true,exclusive:true},function(fileentry){})(fs是文件系统)中,file_path是一个固定的字符串,那么多次执行该语句,程序会报错,错误类型是invalidmodificationerror。解决办法是去掉exclusive:true
对于PERSISTENT文件系统,如果不手动清除,那么多次运行fs.root.getfile(…),会消耗申请的空间,最后文件系统的空间可能被全部消耗完。
这时,再次运行应用程序,可能会出现错误,错误类型是quotaexceedederror。解决办法是清除文件系统,方法如上。