Opening the file in binary mode fixed it, however this wouldn't be needed on a UNIX system.