1

Part of a Google Chrome Extension I am working on has this existing JavaScript below for creating a Blog file from a screenshot image...

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

Looking at saveBlob(blob, filename, callback, errback) above. How long would a file created this way exist? Does it disappear when the browser is closed?

JasonDavis
  • 48,204
  • 100
  • 318
  • 537

1 Answers1

2

The file would exist until directly deleted by user or Clear browsing data is used at settings; though there is no guarantee of persistence.

4.4.1.2 Constants

TEMPORARY of type unsigned short Used for storage with no guarantee of persistence.

See also Temporary storage

guest271314
  • 1
  • 15
  • 104
  • 177
  • I actually just came across this `Data stored using TEMPORARY can be removed at the browser's discretion (for example if more space is needed).` and I see it called here `window.webkitRequestFileSystem(TEMPORARY, 1024*1024,)` – JasonDavis May 02 '16 at 05:48
  • Yes. That is another way a file could be removed from filesystem. You can check if file exists in `FileSystem` using `DevTools` -> `Experiments` -> check `FileSystem inspection` , see http://stackoverflow.com/questions/36098129/how-to-write-in-file-user-directory-using-javascript/ – guest271314 May 02 '16 at 05:49
  • @JasonDavis Try visiting plnkr http://plnkr.co/edit/EVVNYYUvHiM545T06kMC?p=preview , closing chrome, re-launching chrome then at `terminal` `$ ~/.config/chrome/Default/File\ System` , then `$ ls` . The numerical directories listed should contain the files saved to `FileSystem` – guest271314 May 02 '16 at 06:04
  • @JasonDavis Clearing browsing data also delete file in `FileSystem` – guest271314 May 02 '16 at 13:43
  • @ZigMandel In the original form, when I downvoted, it was incorrect and very short without any references. – Xan May 02 '16 at 14:45