use BytesIO instead of StringIO

To support Python 3. And I think it is still backward compatible.

https://docs.python.org/3/library/io.html#buffered-streams
https://docs.python.org/2/library/io.html#buffered-streams