Make sure to open in binary mode.

Also, read() multiple times to be safe on all platforms.