Message from discussion
emit('data') best practice
Received: by 10.66.77.39 with SMTP id p7mr3265948paw.0.1346771759400;
Tue, 04 Sep 2012 08:15:59 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.68.197.72 with SMTP id is8ls22379007pbc.5.gmail; Tue, 04 Sep
2012 08:15:48 -0700 (PDT)
Received: by 10.66.89.163 with SMTP id bp3mr3396807pab.6.1346771748374;
Tue, 04 Sep 2012 08:15:48 -0700 (PDT)
Received: by 10.66.89.163 with SMTP id bp3mr3396806pab.6.1346771748351;
Tue, 04 Sep 2012 08:15:48 -0700 (PDT)
Return-Path: <mikeal.rog...@gmail.com>
Received: from mail-pb0-f43.google.com (mail-pb0-f43.google.com [209.85.160.43])
by gmr-mx.google.com with ESMTPS id qq4si1500435pbb.1.2012.09.04.08.15.48
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 04 Sep 2012 08:15:48 -0700 (PDT)
Received-SPF: pass (google.com: domain of mikeal.rog...@gmail.com designates 209.85.160.43 as permitted sender) client-ip=209.85.160.43;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of mikeal.rog...@gmail.com designates 209.85.160.43 as permitted sender) smtp.mail=mikeal.rog...@gmail.com; dkim=pass header...@gmail.com
Received: by pbbrq2 with SMTP id rq2so13339762pbb.16
for <nodejs@googlegroups.com>; Tue, 04 Sep 2012 08:15:48 -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=4J1GxUyVEqeU1aCjSxpIdLrb8ZpyU8USNuUsw27gukY=;
b=LSFtsp35wc+8YAWE/rlQ5hecFj6/DPIE/4x5Wrd/ZPfN+e0iD2OyQKKo/PpA7v6q3+
ku07zjJDQkecErQ2pmOzGB+1vnzU0K1KGbNHs+Kn5vHnSlYMvSwpx4R6vyM5OSu0NhV5
Gl8fLXx8+6JgxOP46K4pjddC2jzWaC/7lPNlVZv6kjJ1dWRjFWIXG5QkJqwFRjrZ+skT
dtf2x5Tm68vZwQqlCw9KTKYfb8fSSMNdlyRHUTsmLV92ZU8uOG2/K2Unv3WgOyAoeRIp
SyiTLfprGIlzjxohO5RnviDtQ9BA90etwr40ojuRq0Mk8Tg7ZAnRLDytFoXs/4RDCmTP
jyeg==
Received: by 10.68.213.195 with SMTP id nu3mr46476104pbc.81.1346771748158;
Tue, 04 Sep 2012 08:15:48 -0700 (PDT)
Return-Path: <mikeal.rog...@gmail.com>
Received: from [10.0.1.188] (c-24-6-19-200.hsd1.ca.comcast.net. [24.6.19.200])
by mx.google.com with ESMTPS id or1sm12406475pbb.10.2012.09.04.08.15.46
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 04 Sep 2012 08:15:46 -0700 (PDT)
From: Mikeal Rogers <mikeal.rog...@gmail.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_F6B7B0F8-818E-417D-95F6-FCE55D0E498B"
Message-Id: <7D53FB76-5C7D-4832-AF6E-F6536B776...@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 6.0 \(1486\))
Subject: Re: [nodejs] Re: emit('data') best practice
Date: Tue, 4 Sep 2012 08:15:45 -0700
References: <c9a7d898-3544-439b-9636-b91c95b95852@googlegroups.com> <5de16108-9899-4784-8ad6-110b3db07406@googlegroups.com>
To: nodejs@googlegroups.com
In-Reply-To: <5de16108-9899-4784-8ad6-110b3db07406@googlegroups.com>
X-Mailer: Apple Mail (2.1486)
--Apple-Mail=_F6B7B0F8-818E-417D-95F6-FCE55D0E498B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=iso-8859-1
I tend to agree.
The current implementation in most of node allows setEncoding to change =
the data event to emit buffers. In the case of several userland streams =
strings are emitted.
For efficiency, if people are expected to work with the data as a string =
it is much cheaper to avoid unnecessary conversions, but IMO it's =
painful to not be able to assume "data" events will be Buffers.
-Mikeal
On Sep 3, 2012, at September 3, 20128:26 PM, tjholowaychuk =
<tjholoway...@gmail.com> wrote:
> IMO if the idea behind streams are to act like pipes then "data" =
events should only be "raw" data aka Buffers (strings too I guess),
> if it's a non-stream then whatever I guess
>=20
> On Monday, 3 September 2012 15:44:55 UTC-7, Mike Nichols wrote:
> When issuing a redis command which expects a multi-bulk reply but the =
key does not exist, one may receive the following:
> +OK
> *0
>=20
> The redis docs say "If the specified key does not exist, the key is =
considered to hold an empty list and the value 0 is sent as multi bulk =
count."
>=20
> It seems like it is proper to emit a 'data' event in a client library =
with the 'empty list' redis implies so that consuming code can use it in =
a pipeline and let the consumer handle the `empty list` there.
>=20
> This came from looking at 'https://github.com/tblobaum/redis-stream' =
where this sort of reply drops the data, thus breaking the pipeline.=20
>=20
> This leads me to the greater question on whether or not to emit 'data' =
for a empty value. My gut says low level libs like these _should_ emit =
the event with empty data but I wonder what other authors are =
preferring.
>=20
> Any opinions would be appreciated on this.
>=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=_F6B7B0F8-818E-417D-95F6-FCE55D0E498B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=iso-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Diso-8859-1"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><div>I tend to agree.</div><div><br></div><div>The current =
implementation in most of node allows setEncoding to change the data =
event to emit buffers. In the case of several userland streams strings =
are emitted.</div><div><br></div><div>For efficiency, if people are =
expected to work with the data as a string it is much cheaper to avoid =
unnecessary conversions, but IMO it's painful to not be able to assume =
"data" events will be =
Buffers.</div><div><br></div><div>-Mikeal</div><br><div><div>On Sep 3, =
2012, at September 3, 20128:26 PM, tjholowaychuk <<a =
href=3D"mailto:tjholoway...@gmail.com">tjholoway...@gmail.com</a>> =
wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite">IMO if the idea behind streams are to act like pipes then =
"data" events should only be "raw" data aka Buffers (strings too I =
guess),<div>if it's a non-stream then whatever I guess<br><br>On Monday, =
3 September 2012 15:44:55 UTC-7, Mike Nichols wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div>When issuing a redis command =
which expects a multi-bulk reply but the key does not exist, one may =
receive the =
following:<br></div><div>+OK</div><div>*0</div><div><br></div><div>The =
redis docs say "<span style=3D"color:rgb(51,51,51);font-family:'Helvetica =
Neue',sans-serif;line-height:19px;background-color:rgb(250,250,250)">If =
the specified key does not exist, the key is considered to hold an empty =
list and the value </span><code =
style=3D"font:inherit;font-family:Menlo,Monaco,monospace;color:rgb(51,51,5=
1);background-color:rgb(250,250,250)">0</code><span =
style=3D"color:rgb(51,51,51);font-family:'Helvetica =
Neue',sans-serif;line-height:19px;background-color:rgb(250,250,250)"> =
;is sent as multi bulk count."</span></div><div><span =
style=3D"color:rgb(51,51,51);font-family:'Helvetica =
Neue',sans-serif;line-height:19px;background-color:rgb(250,250,250)"><br><=
/span></div><div>It seems like it is proper to emit a 'data' event in a =
client library with the 'empty list' redis implies so that consuming =
code can use it in a pipeline and let the consumer handle the `empty =
list` there.</div><div><br></div><div>This came from looking at '<a =
href=3D"https://github.com/tblobaum/redis-stream" =
target=3D"_blank">https://github.com/tblobaum/<wbr>redis-stream</a>' =
where this sort of reply drops the data, thus breaking the =
pipeline. </div><div><br></div><div>This leads me to the greater =
question on whether or not to emit 'data' for a empty value. My gut says =
low level libs like these _should_ emit the event with empty data but I =
wonder what other authors are preferring.</div><div><br></div><div>Any =
opinions would be appreciated on =
this.</div><div><br></div></blockquote></div><div><br =
class=3D"webkit-block-placeholder"></div>
-- <br>
Job Board: <a =
href=3D"http://jobs.nodejs.org/">http://jobs.nodejs.org/</a><br>
Posting guidelines: <a =
href=3D"https://github.com/joyent/node/wiki/Mailing-List-Posting-Guideline=
s">https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines</a>=
<br>
You received this message because you are subscribed to the Google<br>
Groups "nodejs" group.<br>
To post to this group, send email to <a =
href=3D"mailto:nodejs@googlegroups.com">nodejs@googlegroups.com</a><br>
To unsubscribe from this group, send email to<br>
<a =
href=3D"mailto:nodejs+unsubscribe@googlegroups.com">nodejs+unsubscribe@goo=
glegroups.com</a><br>
For more options, visit this group at<br>
<a =
href=3D"http://groups.google.com/group/nodejs?hl=3Den?hl=3Den">http://grou=
ps.google.com/group/nodejs?hl=3Den?hl=3Den</a><br>
</blockquote></div><br></body></html>=
--Apple-Mail=_F6B7B0F8-818E-417D-95F6-FCE55D0E498B--