<p>I am reading a binary file into a parsing program.  I will need to iterate through the file and look for certain markers so I can split the file up and pass those parts into their respective object’s constructors.</p>

<p>Is there an advantage to holding the file as a stream, either MemoryStream or FileStream, or should it be converted into a byte[] array?</p>

<p>Keith</p>

[{'answer_id': 16957, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 4, 'selected': False, 'text': '<p>A MemoryStream is basically a byte array with a stream interface, e.g. sequential reading/writing and the concept of a current position.</p>\n'}, {'answer_id': 16967, 'author': 'denis phillips', 'author_id': 748, 'author_profile': 'https://Stackoverflow.com/users/748', 'pm_score': 6, 'selected': True, 'text': '<p>A <code>byte[]</code> or <code>MemoryStream</code> will both require bringing the entire file into memory. A <code>MemoryStream</code> is really a wrapper around an underlying byte array. The best approach is to have two <code>FileStream</code> (one for input and one for output). Read from the input stream looking for the pattern used to indicate the file should be separated while writing to the current output file.</p>\n\n<p>You may want to consider wrapping the input and output files in a <code>BinaryReader</code> and <code>BinaryWriter</code> respectively if they add value to your scenario.</p>\n'}]
['https://Stackoverflow.com/questions/16939', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1048/']