buffer writing of compression meta data, and make sure stream is closed