如何在内存中的另一个cab文件中提取cab文件? [英] How to extract cab file within another cab file in memory?

查看:98
本文介绍了如何在内存中的另一个cab文件中提取cab文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为outercab.cab的cab文件和这个名为innercab.cab的cab文件中的另一个cab文件。内部cab文件包含result.xml。有没有办法让我无需写入磁盘即可获取result.xml的内容? (在记忆中做到这一切)?我有这个,它写入磁盘:



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;
    }





这个问题是它不是线程安全的。多人可以从临时文件夹中写入/删除。所以,我想在内存中完成整个过程。目前只有内部驾驶室在内存中解压缩。知道怎么做吗?



我尝试过:



我试过在内存中提取内部驾驶室。但外部cab在提取时,其内容当前写入磁盘,这不是线程安全的。



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.

推荐答案

查看此SO帖子的底部答案 c# - 在内存中解压缩cab文件 - Stack Overflow [ ^ ]
check out the bottom answer on this SO post c# - Unpack cab file in memory - Stack Overflow[^]


这篇关于如何在内存中的另一个cab文件中提取cab文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆