Write partially filled buffer to file.

After terminating the write thread, write all encoded bytes to file so that all
Google protocol buffer messages are complete and decoding works properly.