-
Notifications
You must be signed in to change notification settings - Fork 121
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
Patch stream2 writable v2 #67
Patch stream2 writable v2 #67
Conversation
Pull new master from gridfs-stream
…store is closed. Do not call _write internally. Inherit from FlushWriteable as a workaround to implement a _flush method. Removed destrySoon.
…lush indication is received before the store opens.
It's not strictly required but it makes the code more robust.
Check and set them whenever possible for more robust code.
Like _delayedWrite and _writeInternal; we need to delay the flush during opening, let's do it the same way as _write.
Because _opened can be false even if opening finished (in case of error), and we don't want to delay the write in case of error. It's also done this way for delayed _flush. Normalize comments with delayed _flush too.
…ile is really written (ie after _store.close()
Test open, close, finish events.
Now emits an 'error', because it stops the write before it's finished. Also takes an optional error argument which will be emitted with the 'error' event. Add a test for both features.
…time to the caller to register the callbacks.
It could happen if destroy() is called while _store.open fails.
If destroy() is called during _store open, then _close could be ignored; leaving the _store open.
…ether. Current implementation always calls 'open' and 'close'; it could also just call 'error', in which case we should rewrite this test.
Awesome! thank you. |
@triccardi-systran - Sorry for the late reply: thank you for this! Very cool. Your version has been published as version 1.0.2. |
@Reggino |
(Nevermind for the Chunk leak in case of |
@triccardi-systran Thanks, you're right. I've added the deprecated |
For the error handling questions, I opened a ticket at mongodb: |
Here is a review with fixes and cleanups on top of riaan53/gridfs-stream master, for Writable stream only.
finish
event is emitted when the file is fully on GridFS (using flushwritable).destroy()
emits an error (and the error can be specified as destroy(err), because the write to GridFS may be aborted, so the file is corrupted.open
andclose
(andfinish
)destroy
Pending questions:
I don't know what we should do in case of error:
It works, but we could do other things: _write and _flush give callbacks that accept an error as first argument. If there is either a _write or a _flush (we cannot have both at the same time) running during the error (for example _store.open() failed, or _store.write() failed, or _store.close() failed), then we could (also?) call that callback with the error.
From what I read in the code of nodejs v0.10.31 and v0.12.0, both with indirectly emit error, and the _write() callback will call the optional write() callback so the caller will be notified too. It may be useful to notify the caller this way, but it's harder to do it properly: we need to avoid multiple error emitted, and we still need to call _close() (and maybe in a precise order: it may be useful to guarantee that 'error' happens before (or after?) 'close'; for that we could delay _close() to nextTick). I don't know what is the best practice here... Maybe we should ask on nodejs mailing list?
I haven't reviewed the Readable stream yet, I'm less familiar with Readable streams than with Writable ones...
PS: I patched the commit riaan53@c6ac486 in this branch to remove the wrongly committed temporary file
test/tmp/1mbBlob
.