On Tuesday, March 27, 2012 4:31:58 PM UTC-7, Ben Noordhuis wrote: > > On Wed, Mar 28, 2012 at 00:36, Henry Jen <[email protected]> wrote: > > > > If we consider only 4 characters are valid and used to decode, the result > > octets written would be 3 instead of 4. The buf.write() does write 4 > octets > > and returns 4. > > > > Should this be considered a bug in test or is there a better explanation? > > Or perhaps I misunderstood what _charsWritten means? > > The test is working as expected. The base64 decoder in node (for > better or worse) handles partial input. In this particular case, it > assumes that the input is 8 octets long and that the two missing > octets are padding. > > > Thanks for the reply.
The bytes written is 4 as returned from Buffer.write() function is expected behavior. The value in doubt is Buffer._charWritten. Look at other tests, especially the 'hex' encoding example next, 9 bytes are written, and the "characters" are written is set to 18. Which match to my understanding as "characters in the input string consumed for decoding written octets". In that sense, shouldn't Buffer._charsWritten be set to 6? Assume the input sting to have padding, "123456=" or "123456==", what should be the Buffer._charWritten? 7 and 8 accordingly? Cheers, Henry -- 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
