Add binary mode to write() to fix corrupt files and added tests
Merge pull request #22 from pebreo/pebreo

Fix issue #18. Add binary mode to write() to fix corrupt files and added tests (thanks @pebreo)