繁体   English   中英

在Google Chrome浏览器中创建的Blob文件存在多长时间?

[英]How long does a Blob file created in Google Chrome Exist?

我正在使用的Google Chrome扩展程序的一部分具有以下现有的JavaScript,用于根据屏幕快照图像创建Blog文件...

    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) 以这种方式创建的文件将存在多长时间? 关闭浏览器后它会消失吗?

该文件将一直存在,直到被用户直接删除或在settings使用“ Clear browsing data 尽管不能保证持久性。

4.4.1.2常数

类型为unsigned short TEMPORARY ,用于存储,不保证持久性。

另请参阅临时存储

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM