I'm attempting to serialize a significant amount of binary data out to a custom file format using System.IO.Packaging.Package and PackagePart. I'm attempting to use a BinaryFormatter to output a set of detailed medical imaging datasets to distinct parts within a file/package.
I can use the BinaryFormatter to output all my data directly to a FileStream (not using System.IO.Packaging at all) and my sample data outputs about 140meg of data in around 12 seconds. Pretty fast and not too bad of a solution but I'd prefer a more flexible format supporting compression and the ability to store additional data in a flexible format.
Getting a stream via _packagePart.GetStream() and attempting to serialize data to this stream via a BinaryFormatter cases my data serialization to take about 5 to 10 minutes (and this is with compression turned off).
The System.IO.Packaging.Package class is somewhat of a black box that I don't have significant experience with. Any idea why streaming data to this format vs a direct binary formatter to a file would differ so radically in performance? I know my object can be serialized relatively quickly to a binary format. Why so long to write?