Perhaps several files in one MemoryStream?

Can I save a list of files to a single MemoryStream and save the files later to disk?

+4
source share
1 answer

Well yes, there are several ways to do this, but you would need to do something like this:

class MyFile { public byte[] Data; public string FileName; } List<MyFile> files = GetFiles(); using (MemoryStream stream = new MemoryStream()) { // Serialise BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, files); // Deserailise stream.Position = 0; List<MyFile> deserialisedFiles = (List<MyFile>)formatter.Deserialize(stream); SaveFiles(deserialisedFiles); } 

Where you should be able to understand the implementation of SaveFiles and GetFiles . I don't quite understand why you want to do this, though.

+6
source

Source: https://habr.com/ru/post/1383656/


All Articles