Writing of header fails for async transforms of large files

I have added two tests that demonstrate the bug. The sync test passes and the async test fails.