Reputation: 11
I have a 7z archive containing hundreds of text files. I want to load each text file directly into memory.
This code works, but it is slow:
var memoryStreams = new List<MemoryStream>();
var st = new SevenZipExtractor("files.7z");
for (var i = 0; i < st.FilesCount; i++)
{
var stream = new MemoryStream();
st.ExtractFile(i, stream);
memoryStreams.Add(stream);
}
//Read the memoryStreams - at this point it runs very fast
This takes 15 minutes to run. In comparison it takes ten seconds to unzip to disk, so as a workaround I'm doing exactly that, and then deleting the folder after reading each file into memory. But there must be a better way.
Upvotes: 1
Views: 481