zlib stream.write callback

107 views
Skip to first unread message

khs4473

unread,
Oct 9, 2012, 3:42:36 PM10/9/12
to nod...@googlegroups.com
I see that zlib streams accept a callback to their write method, which will be called when the input buffer is completely read (I'm guessing).  But I don't see documentation of that in the API docs.  Is it safe to use this feature?

Kevin

Isaac Schlueter

unread,
Oct 9, 2012, 3:58:21 PM10/9/12
to nod...@googlegroups.com
No, it is going away in 0.10, with the stream API cleanup.
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

khs4473

unread,
Oct 9, 2012, 4:09:02 PM10/9/12
to nod...@googlegroups.com, i...@izs.me
Cool - are new-style streams and old-style streams going to coexist in 0.10, or is everything being moved over to new-style?

Kevin

Isaac Schlueter

unread,
Oct 9, 2012, 4:14:07 PM10/9/12
to khs4473, nod...@googlegroups.com
If you add a listener on the 'data' event, or call .pause() or
.resume(), then new style streams will switch into old-style. So,
existing programs should Just Work, but there are a bunch of new
classes that you'll be able to use to extend in userland streams so
that they play nicely with everything else.

khs4473

unread,
Oct 9, 2012, 9:52:24 PM10/9/12
to nod...@googlegroups.com
Hmmm...

I'd like very much to have a way to determine when zlib is done with a buffer, but without using the callback it appears to be a black hole of sorts for whatever I put in.

I'm all for allocating like mad and using the GC to manage things, but I would also like to have the option of micro-managing buffers if I choose.  It's systems programming, right? : )

Kevin

Isaac Schlueter

unread,
Oct 10, 2012, 1:05:34 AM10/10/12
to nod...@googlegroups.com
Ok, fair enough. Writable stream write() callbacks landed on streams2 branch.

khs4473

unread,
Oct 10, 2012, 10:34:35 AM10/10/12
to nod...@googlegroups.com
Too nice : )

I could be misguided, but I find that I gravitate toward low-level IO, like the interface that fs provides.  The cool thing about fs (not the streams, but the posix functions), is that I can wrap them in whatever abstraction makes sense at the time.  I can create my own stream classes around it, or I can make it callback-based or promise-based if I prefer.  At the lowest level, it's pure simplicity:

    read: 
      fill this buffer with this many bytes, please, and call this 
      function when yer done (and let me know how much you 
      wrote).

    write: 
      write this many bytes from this buffer and let me know when
      you're done with said buffer.


Kevin

Mikeal Rogers

unread,
Oct 10, 2012, 10:38:07 AM10/10/12
to nod...@googlegroups.com
wait, what? *all* readable streams have a write() callback now?

-Mikeal

Isaac Schlueter

unread,
Oct 10, 2012, 11:49:43 AM10/10/12
to nod...@googlegroups.com
No, all *writable* streams in core will, and the Writable base class will provide it. 
Reply all
Reply to author
Forward
0 new messages