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.