If I wanted to fill a structure from a binary file, I would use something like this:
using (BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)))
{
myStruct.ID = br.ReadSingle();
myStruct.name = br.ReadBytes(20);
}
However, I must read the whole file into a byte array before deserializing, because I want to do some pre-processing. Is there any managed way to fill my structure from the byte array, preferably similar to the one above?
This is a sample to take some data (actually a System.Data.DataSet) and serialize to an array of bytes, while compressing using DeflateStream.
Here is the code in reverse to deserialize:
Hope this helps. As Nate implied, we are using MemoryStream here.