Add data to mac before writing out the stream

Summary:
Writes data to the mac before writing out to
the stream.

This makes it more secure in presence of bugs
which partially write bytes to disk.

Test Plan:
integration tests.
Merge pull request #22 from facebook/write_after_mac

Add data to mac before writing out the stream