Always write files in binary mode.

Fixes #205. Includes tests. Supports transactions (also tested).