Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
    {
        //Unpack outer cab to get innercab.cab and place in temp folder
        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))
        {
            //Extract innercab.cab in memory to access results.xml contents
            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.
Posted
Updated 20-Apr-16 14:47pm

1 solution

check out the bottom answer on this SO post c# - Unpack cab file in memory - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900