On Thu, Dec 27, 2012 at 8:51 PM, am_p1 <andrewmcintyr...@gmail.com> wrote:
> Just fyi, I never get an "end" since this is streaming... just "data" always
> and always... and 99.99% of them are not split chunks, ie; they are complete
> and valid XML.
>
> So I've got the merging back together mostly working but it's a pain and
> it's still not 100%, I assume due to me trying to merge them back together
> in UTF8 strings. Maybe I should be doing it with a buffer instead? cause I
> read the chunks could be split in the middle of the UTF8 encoding... yikes!!
>
> This cleared up most of it but again, still not 100%.
> str = (save + data).toString('utf8')
>
> And shouldn't node.js be handling this somehow? ( he asked not knowing
> hardly anything about node.js - this is my first post!!! )
>
> Thanks for any assistance!!

stream.setEncoding('utf8') will take care of partial multi-byte
sequences.  Your data event listener will receive strings instead of
buffers.

Alternatively, you can concat the buffers together.  The buffertools
module has a helper for that but it's quite trivial to implement one
yourself:

  // a and b are the input buffers
  var c = new Buffer(a.length + b.length);
  a.copy(c, 0);
  b.copy(c, a.length);

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to