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.
Is there an advantage to holding the file as a stream, either MemoryStream or FileStream, or should it be converted into a byte[] array?
Keith
A
byte[]orMemoryStreamwill both require bringing the entire file into memory. AMemoryStreamis really a wrapper around an underlying byte array. The best approach is to have twoFileStream(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.You may want to consider wrapping the input and output files in a
BinaryReaderandBinaryWriterrespectively if they add value to your scenario.