Header write function for memory stream.