I have a cab file called "outercab.cab" and another cab file within this cab file called "innercab.cab". The inner cab file contains "result.xml". Is there a way for me to get the contents of result.xml without having to write to disk? (Do it all in memory)? I have this, which writes to disk:
public string GetResults(string pathToOuterCab)
{
var cabToUnpack = new CabInfo(pathToOuterCab);
string tempEnvironmentPath = "C:\SomePath\Temp";
cabToUnpack.Unpack(tempEnvironmentPath);
CabEngine engine = new CabEngine();
FileStream innerCab = new FileStream(tempEnvironmentPath + @"\innercab.cab", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
foreach (ArchiveFileInfo archiveFileInfo in engine.GetFileInfo(innerCab))
{
Stream stream = engine.Unpack(innerCab, archiveFileInfo.Name);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
string xml = Encoding.UTF8.GetString(buffer);
DirectoryInfo tempDirectory = new DirectoryInfo(@"C:\SomePath\Temp");
foreach(System.IO.FileInfo file in tempDirectory.GetFiles())
{
file.Delete();
}
innerCab.Close();
return xml;
}
return null;
}
The problem with this is that it is not thread safe. Multiple people can be writing/deleting from the temp folder. So, I want to do the whole process in memory. Currently only the inner cab is unpacked in memory. Any idea how to do this?
What I have tried:
I've tried extracting the inner cab in memory. But the outer cab, when extracted, its contents are currently written to disk, which is not thread safe.