On Thu, Mar 28, 2013 at 12:54 AM, W. David Jarvis
If I compare the len() of the two strings (pre-writing/reading v. post-writing/reading) I tend to get two add'l chars on the reading, so I guess I'm confused by how this is getting truncated? Is python running into a newline char and interpreting it literally somehow?
Don't use 'print', use file.write(). Using print adds a newline (or probably CRLF in your case). The encoded form is not self-delimiting so if you include an extra CRLF in the bytes given to the decoder, it'll happily try to interpret them, and then run out of data because the decoder's interpretation of the extra bytes implies there should be more data following them.
I wouldn't rely on sys.stdout being binary-safe either. The encoded forms are binary, not text - you should treat them as such - if any conversion of linefeeds happens, it will corrupt the message.
Oliver