0

I want to serialize/deserialize multiple object from/to a file. The syntax should be similar to this:

obj.Append(byteArray);
obj.Append(byteArray);
obj.Append(byteArray);
IEnumerable<byte[]> obj.Extract();

While this is very simple to accomplish (e.g., write a class that uses a filestream and protobuf-net internally), I'm wondering if there is any more elegant way of doing this. Is there any class (from a third party library), that uses a serializer to write to an filestream?

Edit: I need this as a filestream that captures video data that is sent through network. So the filestream must be open for a dedicated amount of time. My previous solution was to save every video frame to a new file, but it's not scalable (especially for hdd, and increasing video partners).

4

1 回答 1

0

关于什么:

using(var stream = File.Open(filename, FileMode.Create))
{
      var formatter = new BinaryFormatter();
      formatter.Serialize(stream, firstObjectToSerialize);
      formatter.Serialize(stream, secondObjectToSerialize);
}
于 2012-07-13T17:04:27.260 回答