Mike Pateras
Mike Pateras

Reputation: 15015

Can't get a node stream's finish event to fire

I'm trying to determine when a node WriteStream is done writing:

var gfs = GFS(db);

var writeStream = gfs.createWriteStream(
{
    filename: "thismyfile.txt",
    root: "myfiles"
});

writeStream.on("finish", function()
{
    console.log("finished");
    response.send({ Success: true });
});

writeStream.write("this might work");
writeStream.end();

console.log("end");

In my console, I see "end", but never "finished", and there is never a response. The stream is writing properly, however, and it seems to be finishing (I see the completed file in the database). That even just isn't firing. I've tried moving the "this might work" into the call to end() and removing write(), I've also tried passing a string into end() as well. That string is written to the stream, but still no callback.

Why might this event not be getting fired?

Thank you.

Upvotes: 2

Views: 908

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161457

The gridfs-stream module is designed and written primarily for node 0.8.x and below and does not use the stream2-style methods provided by require('stream').WritableStream in node >= 0.10.x. Because of this, it does not get the standardized finish event. It is up to the module implementation itself to emit finish, which it apparently does not.

Upvotes: 1

Related Questions