Call the callback when you're ready to get more chunks.

If that means "I've stashed this, but I need to see more before I can
do anything," then that's fine.

You don't have to stash the callback anywhere.  It's the same function
each time :)


On Sun, Apr 14, 2013 at 9:03 AM, Mike Pilsbury <[email protected]> wrote:
>> I have technically consumed it by hanging on to it.
>
> That's the bit that I was concerned about. I wasn't sure that I could rely
> on the Buffer's contents remaining valid until I used it.
>
> It's good to know that I can take the simple approach. Thanks.
>
>
> On Sunday, 14 April 2013 16:57:17 UTC+1, Tom Dunn wrote:
>>
>> Here's what I have done in the past, if I get an incomplete chunk, I  hang
>> on to it and call done, I have technically consumed it by hanging on to it.
>> When I get another chunk I check if that completes my partial chunk, if it
>> does, I do this.push then call done, if I don't I hang to another partial
>> chunk and call done anyways.
>>
>> Instead of hanging on to the callback (done), just call it once you've put
>> your partial chunk on to your _pendingChunks array
>>
>> On Sunday, 14 April 2013 07:16:18 UTC-4, Mike Pilsbury wrote:
>>>
>>> I'm extending Transform, and I'm a little unclear when to call
>>> transform._transform(chunk, encoding, callback)'s callback.
>>>
>>> The documentation says "Call the callback function only when the current
>>> chunk is completely consumed. Note that there may or may not be output as a
>>> result of any particular input chunk.". But what does "completely consumed"
>>> mean?
>>>
>>> If I can't use the chunk yet (because I need to wait for more data for a
>>> full packet, and the packet's length has to be in the packet's header), and
>>> I keep a reference to the chunk, does that mean that I shouldn't call the
>>> callback yet? If that's the case, I guess that I need to keep the callback
>>> associated with each of these chunks.
>>>
>>>     this._pendingChunks = [];
>>>     ...
>>>     this._pendingChunks.push({chunk: chunk, callback: callback});
>>>
>>> Then I can call each chunk's callback (in a latter execution of
>>> _transform) when I've used it to create and push a complete packet, and I've
>>> no longer a need to reference the chunk.
>>>
>>> Or am I making things more complicated than they need to be?
>>>
> --
> --
> 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.
>
>

-- 
-- 
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