Received: by 10.180.73.173 with SMTP id m13mr1463383wiv.4.1350160434387; Sat, 13 Oct 2012 13:33:54 -0700 (PDT) X-BeenThere: nodejs@googlegroups.com Received: by 10.180.90.134 with SMTP id bw6ls4312355wib.1.canary; Sat, 13 Oct 2012 13:33:05 -0700 (PDT) Received: by 10.180.94.98 with SMTP id db2mr1469697wib.2.1350160385293; Sat, 13 Oct 2012 13:33:05 -0700 (PDT) Received: by 10.180.94.98 with SMTP id db2mr1469696wib.2.1350160385267; Sat, 13 Oct 2012 13:33:05 -0700 (PDT) Return-Path: Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by gmr-mx.google.com with ESMTPS id hm1si217686wib.3.2012.10.13.13.33.05 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 13 Oct 2012 13:33:05 -0700 (PDT) Received-SPF: pass (google.com: domain of mikeal.rog...@gmail.com designates 74.125.82.52 as permitted sender) client-ip=74.125.82.52; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mikeal.rog...@gmail.com designates 74.125.82.52 as permitted sender) smtp.mail=mikeal.rog...@gmail.com; dkim=pass header...@gmail.com Received: by mail-wg0-f52.google.com with SMTP id fg15so3033747wgb.9 for ; Sat, 13 Oct 2012 13:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to:x-mailer; bh=RpF7MPbC5mGrbDZvfTydJaS5BEy7thAFoCV+mD2aVCo=; b=tDAqsfmqRMnV1pEyAc+o4zExb/TcJsU9VIMEr5fAxYS46PwweifZIAxzB1yH5oKyMB bTbXm55rZQlPEx9ndRDDoFW6uET1kjuJcW7Mc9z3kIGEvXmt5m+vEXjJ3enUyu/g1f3X DQHnE0U7ZUnvA+hbNttBSG7KEkVVqkDitmaiiolYL9suRExJy/kJIaTDEnxJTngwkr4M 6SBI0pqcNGHvuAg6ylUkOz2SGR7vvvRUsCkXZc4Y1fxhVEvhP1mVS3z2rpd7o2WlLAcp w+UFcx0WxeU+C9JksqzKnsM5GldA32xNnbL8Kvbmv/lDCMJf+yncjTQ1qRufTjaciwpH OI5A== Received: by 10.180.85.99 with SMTP id g3mr13851039wiz.5.1350160385069; Sat, 13 Oct 2012 13:33:05 -0700 (PDT) Return-Path: Received: from [192.168.2.194] (p5B172A3D.dip.t-dialin.net. [91.23.42.61]) by mx.google.com with ESMTPS id cu1sm4942270wib.6.2012.10.13.13.33.02 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 13 Oct 2012 13:33:04 -0700 (PDT) From: Mikeal Rogers Content-Type: multipart/alternative; boundary="Apple-Mail=_87558070-80BD-4546-BEF5-BF372BBAD744" Message-Id: Mime-Version: 1.0 (Mac OS X Mail 6.1 \(1498\)) Subject: Re: [nodejs] Re: How to write stream chunk by chunk with callbacks Date: Sat, 13 Oct 2012 22:33:00 +0200 References: <42eeb107-5160-4b41-9c77-3e3dc781585e@googlegroups.com> <1d8a2240-6830-4b59-9722-3d7f1755dbfe@googlegroups.com> To: nodejs@googlegroups.com In-Reply-To: <1d8a2240-6830-4b59-9722-3d7f1755dbfe@googlegroups.com> X-Mailer: Apple Mail (2.1498) --Apple-Mail=_87558070-80BD-4546-BEF5-BF372BBAD744 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 i'm not engaging with your strawman Bruno. i showed how we *actually* move data in node. this is not a debate, = that's how it works. if anyone wants to use node, or write a module that = has a stream that moves data, that's how they do it. this was a question, not an open invitation for bikeshedding. please let = the list answer questions. On Oct 13, 2012, at October 13, 20128:04 PM, Bruno Jouhier = wrote: > What's wrong?=20 >=20 > You'll find links to gists at the end of my post. The code works! > And Alexey's pumping function is equivalent to the pumping loop I gave = in my post. >=20 > On Saturday, October 13, 2012 7:31:54 PM UTC+2, Mikeal Rogers wrote: > all of these are wrong. >=20 > inputStream.pipe(outputStream) > outputStream.on('close', callback) >=20 > On Oct 13, 2012, at October 13, 20127:23 PM, Bruno Jouhier = wrote: >=20 >> I wrote a post about plain callback APIs for streams: = http://bjouhier.wordpress.com/2012/07/04/node-js-stream-api-events-or-call= backs/ >>=20 >>=20 >> On Saturday, October 13, 2012 11:17:13 AM UTC+2, Alexey Petrushin = wrote: >> I don't quite understand how steam pause/resume works, or more = exactly - how to use it in simple manner. It's necessary to use it in = situations when the read stream produces data faster than the write = stream can consume.=20 >>=20 >> I need to write custom stream implementation and writing it with = proper handling of `pause/resume` functionality seems not a very easy = task. >>=20 >> Plain callbacks seems simpler to me, can streams be somehow wrapped = into a code like that ( code with highlighting = https://gist.github.com/3883920 ) ? >>=20 >> var copy =3D function(inputStream, outputStream, callback){ >> var copyNextChunk =3D function(){ >> inputStream.read(fuction(err, chunk){ =20 >> if(err) return callback(err) >> // When chunk =3D=3D null there's no data, copying is = finished. >> if(!chunk) return callback() >> outputStream.write(chunk, function(err){ >> // Callback called only when chunk of data=20 >> // delivered to the recipient and >> // we can send another one. >> if(err) return callback(err) >> copyNextChunk() >> }) =20 >> }) >> } >> } >>=20 >> --=20 >> 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=3Den?hl=3Den >=20 >=20 > --=20 > 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 nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscribe@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=3Den?hl=3Den --Apple-Mail=_87558070-80BD-4546-BEF5-BF372BBAD744 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=iso-8859-1 bjouh...@gmail.com> = wrote:
What's wrong?

You'll find links to gists at the = end of my post. The code works!
And Alexey's pumping function is = equivalent to the pumping loop I gave in my post.

On Saturday, = October 13, 2012 7:31:54 PM UTC+2, Mikeal Rogers wrote:
all of these are = wrong.

inputStream.pipe(outputStream)
o= utputStream.on('close', callback)

On Oct 13, 2012, at = October 13, 20127:23 PM, Bruno Jouhier <bjou...@gmail.com> = wrote:

I wrote a post about plain = callback APIs for streams: http://bjouhier.wordpress.com/2012/07/04/node-js-st= ream-api-events-or-callbacks/


On Saturday, October = 13, 2012 11:17:13 AM UTC+2, Alexey Petrushin wrote:
I don't quite understand how steam = pause/resume works, or more exactly - how to use it in simple = manner. It's necessary to use it in situations when the read stream = produces data faster than the write stream = can consume. 

I need to write custom = stream implementation and writing it with proper handling of = `pause/resume` functionality seems not a very easy = task.

Plain callbacks seems simpler to me, can = streams be somehow wrapped into a code like that ( code with = highlighting https://gist.github.com/3883920 ) = ?

    var copy =3D = function(inputStream, outputStream, callback){
    =   var copyNextChunk =3D function(){
      =   inputStream.read(fuction(err, chunk){   =  
          if(err) return = callback(err)
          // When chunk = =3D=3D null there's no data, copying is finished.
  =         if(!chunk) return = callback()
          = outputStream.write(chunk, function(err){
      =       // Callback called only when chunk of = data 
            // = delivered to the recipient and
        =     // we can send another one.
      =       if(err) return callback(err)
  =           copyNextChunk()
  =         })  
      =   })
      }
    = }

--
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<= /a>
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=3Den?hl=3D= en


--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@goo= glegroups.com
For more options, visit this group at
http://grou= ps.google.com/group/nodejs?hl=3Den?hl=3Den

= --Apple-Mail=_87558070-80BD-4546-BEF5-BF372BBAD744--