fix write for very large files.

@wvanbergen