Am Samstag, 30. März 2013 13:55:10 UTC+1 schrieb kyogron:
>
> I am currently studying the stream api.
> In the below example from the api docs "unshift" is used to reparse chunk 
> which belongs to the body and not the header.
>

On Saturday, March 30, 2013 8:53:13 AM UTC-6, kyogron wrote:
>
> Ah now I understand it.
>
> this.unshift really only puts the chunk in front of the buffer which than 
> will get emitted. 
> If there will come some more body chunk than it will pushed as normal.
>
> I just do not get the use case actually. 
> I mean in the given case it would actually not matter if we use unshift or 
> push because it will be the first item in the buffer array anyway.
>
> Is this correct that this is a bad example or have I missed something?
>
>
I think you're right; in this case this.unshift is only called when nothing 
has ever been pushed so it will be the first item in the array.

It may be more instructive to replace:

      // now, because we got some extra data, unshift the rest
      // back into the read queue so that our consumer will see it.
      var b = chunk.slice(split);
      this.unshift(b);

with:

      // now, because we got some extra data, unshift the rest
      // back into the source so that we will see it.
      var b = chunk.slice(split);
      this._source.unshift(b);

      // try again; next time we'll take the this._inBody
      // path and see the b which was just unshifted.
      this.push('');

-- 
-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to