Track the state of file write callbacks.

To make sure all the write callbacks are called before the write stream has
ended. Fixes #210

Signed-off-by: Tim Smart <tim@fostle.com>