Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onwriteend callback not called #1

Closed
mgiulio opened this issue Sep 27, 2011 · 5 comments
Closed

onwriteend callback not called #1

mgiulio opened this issue Sep 27, 2011 · 5 comments

Comments

@mgiulio
Copy link

mgiulio commented Sep 27, 2011

Hello, I am planning to use HTML5(where supported) as an alternative to Downloadify in the custom download builder for the jQuery Lifestream plugin. So, because I am still new to the various File APIs I started to use your script.

I need to monitor the download completion. I followed your relative code snippet example:

var filesaver = saveAs(blob, "secret stuff that you won't send to a server.truecrypt");
filesaver.onwriteend = function() {
    // file saved, do something here
};

but the callback was never called because the event is fired before its registration.

I patched the script in this way:

diff --git a/download/js/FileSaver.js b/download/js/FileSaver.js
index 445c0ae..c2eeeaf 100644
--- a/download/js/FileSaver.js
+++ b/download/js/FileSaver.js
@@ -68,7 +68,8 @@ var saveAs = saveAs || (function(view) {
                }
            }
        }
-       , FileSaver = function(blob, name) {
+       , FileSaver = function(blob, name, afterDownload) {
+      this.onwriteend = afterDownload;
            // First try a.download, then web filesystem, then object URLs
            var
                  filesaver = this
@@ -186,8 +187,8 @@ var saveAs = saveAs || (function(view) {
            }), fs_error);
        }
        , FS_proto = FileSaver.prototype
-       , saveAs = function(blob, name) {
-           return new FileSaver(blob, name);
+       , saveAs = function(blob, name, afterDownload) {
+        return new FileSaver(blob, name,afterDownload);
        }
    ;
    FS_proto.abort = function() {

Is there a better/proper way to do this?

Thanks in advance.

@asyazwan
Copy link

I'm also having this issue. I'm unsure if I missed something obvious or it really is too late by the time I passed onwriteend function...

@eligrey
Copy link
Owner

eligrey commented Jan 24, 2013

Since I can't actually tell when a file is finished writing to the user's filesystem this method isn't really possible to implement so it's going to just be for show in the meanwhile. I'll probably remove onwriteend altogether at a later time.

@eligrey eligrey closed this as completed Jan 24, 2013
graingert pushed a commit to graingert/FileSaver.js that referenced this issue May 26, 2016
@jimmywarting
Copy link
Collaborator

Old issue, I know... But StreamSaver.js is able to do this. Will only work in chrome atm

const fileStream = streamSaver.createWriteStream('filename.txt')
const blobStream = streamSaver.createBlobReader(blob)

blobStream.pipeTo(fileStream).then(() => {
  console.log("done")
})

@bes1002t
Copy link

bes1002t commented Jul 6, 2020

is there any progress made over the years? Perhaps some new Browser features which allow this now?

@jimmywarting
Copy link
Collaborator

Filesaver is sync so no there is none and never will be included in this lib.

However, this might help you do async wires and do progress monitor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants