Perhaps you could try using readb and writeb.
I'm not sure why it doesn't work otherwise, but it points to something about interpreting the bytes as characters.
-----