我正在处理的Google Chrome扩展程序的一部分,下面是现有的JavaScript,用于从屏幕截图中创建博客文件......
getBlob = function(canvas) {
// standard dataURI can be too big, let's blob instead
// http://code.google.com/p/chromium/issues/detail?id=69227#c27
var dataURI = canvas.toDataURL(),
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs
byteString = atob(dataURI.split(',')[1]),
// separate out the mime component
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0],
// write the bytes of the string to an ArrayBuffer
ab = new ArrayBuffer(byteString.length),
ia = new Uint8Array(ab),
i;
for (i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], {type: mimeString});
},
saveBlob = function(blob, filename, callback, errback) {
var onWriteEnd = function() {
// Return the name of the file that now contains the blob.
callback('filesystem:chrome-extension://' + chrome.runtime.id + '/temporary/' + filename);
};
window.webkitRequestFileSystem(TEMPORARY, 1024*1024, function(fs){
fs.root.getFile(filename, {create:true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = onWriteEnd;
fileWriter.write(blob);
}, errback);
}, errback);
}, errback);
},
查看上面的saveBlob(blob, filename, callback, errback)
。以这种方式创建的文件存在多长时间?浏览器关闭时它会消失吗?
答案 0 :(得分:2)
该文件将一直存在,直到被用户直接删除或Clear browsing data
用于settings
;虽然不能保证持久性。
类型为TEMPORARY
的
unsigned short
用于存储时没有 坚持不懈。