aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

WriteStream close event #5

Closed diogogmt closed 12 years ago

diogogmt commented 12 years ago

In a project I'm working on, we decided to use the gridfs-stream module to interact with the GridStore native mongodb driver.

Everything worked just fine, expect in one use case where we were using the Step lib to perform several asynchronous calls, the basic flow was:

Crop original image to create thumbnail Save thumbnail on GridFs Save thumbnail ID in our media obj(mongoose model) Save original image on GridFs Save original image ID in our media obj Save media obj

The problem with this approach was that the close event for the WriteStream didn't return the object added to the GridFs db, so we had to make two extra calls to the GridFs db to get back their IDs to reference them in the media obj.

The proposed patch sends the file added to the GridFs db as an argument in the WriteStream close event, this way it will be possible to manipulate the properties of the newly created file in the GridFs db later in the code. Also if any error happens the close event will get a reference to it.

I added a unit test to check the changes to this patch.

aheckmann commented 12 years ago

looks pretty good except for passing the err to close. thats what the error event is for.

aheckmann commented 12 years ago

looks good, will test / merge tomorrow

aheckmann commented 12 years ago

merged!

aheckmann commented 12 years ago

released in 0.3.2