You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com
I had the impression that _write() was the only method required in a stream.Writable subclass; is an end() implementation required to detect calls to end()?
This code shows that implementing _write() in a stream.Writable implementation won't detect a call to end()
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com, i...@izs.me
We need to make an async call to clean up our writable stream implementation, before emitting finish.
Isaac Schlueter
unread,
Apr 15, 2013, 5:10:28 PM4/15/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Liam, nodejs
Usually "clean up" means "close" rather than "finish". The "finish"
event simply means that all the data has been written, not necessarily
that any underlying resources have been cleaned up.
You could listen on "finish" and do it then.
If it's a Transform stream, and you need to make sure that you flush
something to the output after the last chunk is processed, you can
implement a `_flush(callback)` method.
Nathan Rajlich
unread,
Apr 15, 2013, 6:37:48 PM4/15/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nodejs, Liam
FWIW I volleyed for _flush() to be part of the Writable API directly, rather than Transform, before streams2 were solidified. I had the use-case at the time and apparently Liam does as well. C'est la vie.
Isaac Schlueter
unread,
Apr 16, 2013, 11:40:35 AM4/16/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com, Liam
We could move this into Writable pretty easily. It's an API change, but certainly not unreasonable for 0.12, since it wouldn't be a breaking change.
Liam Breck
unread,
Apr 16, 2013, 1:53:17 PM4/16/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Isaac Schlueter, nod...@googlegroups.com
So _flush would be called when .end() is called by the client of the writable stream?
That seems like an essential feature of a writable stream.
Liam Breck
unread,
Apr 17, 2013, 4:09:13 AM4/17/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com, Isaac Schlueter
It is not essential in the sense that you can already do something similar by listening to the 'finish' event. However observing oneself is a strange pattern. but one implentation of _flush could easily be:
this.on('finish', this._flush);
is that correct ?
Liam Breck
unread,
Apr 17, 2013, 4:26:02 AM4/17/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com, Isaac Schlueter
Only if the 'finish' event could be suppressed by _flush() for other listeners, which I don't see a way to do...
Alternatively the subclass can violate the defined API, and emit 'really_finished' from _flush()
Liam Breck
unread,
Apr 17, 2013, 3:12:26 PM4/17/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com, Isaac Schlueter
[responding on list]
We're talking about flushing left-over data in a scenario where data is written in blocks, for example. The last write callback hasn't fired when end() is called; or write callbacks might simply fire on nextTick unless we paused writing out blocks.
Flushing on 'finish' works only if there's no one else listening on 'finish'. And then our stream subclass doesn't conform to the Writable API.
On Wed, Apr 17, 2013 at 11:40 AM, Isaac Schlueter <i...@izs.me> wrote:
Well,
you shouldn't be calling the write callback until that chunk is
"flushed" anyway, right? Seems like listening to your own finish event
is probably fine. Maybe I'm missing something still?