使用 C# 读取 RAR 文件的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1025863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:49:21  来源:igfitidea点击:

Read content of RAR files using C#

c#streamrar

提问by Peter

Is there any way to read the content of a RAR file (support for multi-file RAR is a must)?

有没有办法读取RAR文件的内容(必须支持多文件RAR)?

I don't want to extract the content to the disk, just read it like a stream.

我不想将内容提取到磁盘,只是像流一样读取它。

采纳答案by arbiter

Low level lib to work with 7z.dll (supports rar archives, incliding multi-part, works with .net streams):

与 7z.dll 一起使用的低级库(支持 rar 档案,包括多部分,与 .net 流一起使用):

C# (.net) interface for 7-Zip archive dlls

7-Zip 存档 dll 的 C# (.net) 接口

And more high-level lib based on the first one:

以及基于第一个的更多高级库:

SevenZipSharp

SevenZipSharp

回答by RvdK

回答by Stefan Steiger

Another possibility is using including the rar command-line executable as application ressource and call it via System.Diagnostics.Process.

另一种可能性是使用包含 rar 命令行可执行文件作为应用程序资源并通过 System.Diagnostics.Process 调用它。

You may want to redirect the input/output stream.

您可能想要重定向输入/输出流。

回答by adamhathcock

My unrar project, http://nunrar.codeplex.com/aims to be very .NETty and has streaming support. If you need something else, please suggest or give me a patch.

我的 unrar 项目http://nunrar.codeplex.com/旨在成为非常 .NETty 并支持流媒体。如果您需要其他东西,请建议或给我一个补丁。

回答by Gfy

If you want to directly access files stored in uncompressedrar files, then this answermight be of use.

如果您想直接访问存储在未压缩rar 文件中的文件,那么这个答案可能有用。

ReSceneis a project for recreating rar archives from the extracted files. You need a .srr file for this. The source code is available. You may want to take a look at RarStream.cs.

ReScene是一个用于从提取的文件中重新创建 rar 档案的项目。为此,您需要一个 .srr 文件。源代码可用。你可能想看看RarStream.cs

回答by Syam Kumar

Install NUnrar from nuget

从 nuget 安装 NUnrar

RarArchive file = RarArchive.Open("rar file path");//@"C:\test.rar"
                    foreach (RarArchiveEntry rarFile in file.Entries)
                    {
                        string path = "extracted file path";//@"C:\"
                        rarFile.WriteToDirectory(path);

                    }