You need to reset the buffer position before starting. You can do this by running buff.seek(0) .
Each time you read or write to the buffer, the position advances by one. Say you start with an empty buffer.
Buffer value "" , pos buffer - 0 . You do buff.write("hello") . Obviously, the buffer value is now hello . However, the buffer position is now 5 . When you call read() , there is nothing previous to position 5 to read! Thus, it returns an empty string.
Joel Cornett Apr 22 '12 at 6:00 2012-04-22 06:00
source share