Added write_stream_flags() to write the state of certain flags into