Minimize string decoding and move to use a bytearray for the buffer. This reduces memory consumption and is faster than the += operator for buffer concatenation and trimming.
Cosmetic edits.
Merge branch 'fix-stream' into pr-fix-stream