简体   繁体   English

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

[英]Read content of RAR files using C#

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. 我不想将内容提取到磁盘,只是像流一样读取它。

Low level lib to work with 7z.dll (supports rar archives, incliding multi-part, works with .net streams): 低级lib与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: 而更高级的lib基于第一个:

SevenZipSharp SevenZipSharp

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

                    }

My unrar project, http://nunrar.codeplex.com/ aims to be very .NETty and has streaming support. 我的unrar项目, http: //nunrar.codeplex.com/旨在成为非常.NETty并拥有流媒体支持。 If you need something else, please suggest or give me a patch. 如果您还需要其他东西,请建议或给我一个补丁。

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. 您可能希望重定向输入/输出流。

If you want to directly access files stored in uncompressed rar files, then this answer might be of use. 如果要直接访问存储在未压缩的 rar文件中的文件,则可能会使用此答案

ReScene is a project for recreating rar archives from the extracted files. ReScene是一个从提取的文件中重新创建rar存档的项目。 You need a .srr file for this. 你需要一个.srr文件。 The source code is available. 源代码可用。 You may want to take a look at RarStream.cs . 您可能想看一下RarStream.cs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM