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.