Completed port of BufIo from python