sharpziplib FastZip extract rar错误无法找到中央目录c#

问题描述 投票:0回答:2

我想使用FastZip提取RAR文件,这是我的代码:

 FastZip fastZip = new FastZip();
                     fastZip.CreateEmptyDirectories = true;
 if (password != "")
                        {
                            fastZip.Password = password;
                        }

                        string fileFilter = null;

                        fastZip.ExtractZip(CompressedFilePathValue, OutputFolderPathValue, fileFilter);

但是我总是会出错:

 cannot find central directory

RAR文件正常,我可以使用WinRAR正确打开它,因此如何使用带有FastZip或不带FastZip的Sharpziplib提取RAR文件?注意:我不想使用SharpCompress,因为我不支持密码。有什么方法可以使用sharpziplib提取RAR文件?感谢您的帮助

c# rar sharpziplib fastzip
2个回答
0
投票

[SevenZipSharp支持rar存档和密码。


0
投票

这里是如何提取RAR文件,没有错误,找不到中央目录:

   using (Stream fs = File.OpenRead(CompressedFilePathValue))
                    using (var zf = new ZipFile(fs))
                    {

                        if (!String.IsNullOrEmpty(password))
                        {
                            // AES encrypted entries are handled automatically
                            zf.Password = password;
                        }

                        foreach (ZipEntry zipEntry in zf)
                        {
                            if (!zipEntry.IsFile)
                            {
                                // Ignore directories
                                continue;
                            }
                            String entryFileName = zipEntry.Name;
                            // to remove the folder from the entry:
                            //entryFileName = Path.GetFileName(entryFileName);
                            // Optionally match entrynames against a selection list here
                            // to skip as desired.
                            // The unpacked length is available in the zipEntry.Size property.

                            // Manipulate the output filename here as desired.
                            var fullZipToPath = Path.Combine(OutputFolderPathValue, entryFileName);
                            var directoryName = Path.GetDirectoryName(fullZipToPath);
                            if (directoryName.Length > 0)
                            {
                                Directory.CreateDirectory(directoryName);
                            }

                            // 4K is optimum
                            var buffer = new byte[4096];

                            // Unzip file in buffered chunks. This is just as fast as unpacking
                            // to a buffer the full size of the file, but does not waste memory.
                            // The "using" will close the stream even if an exception occurs.
                            using (var zipStream = zf.GetInputStream(zipEntry))
                            using (Stream fsOutput = File.Create(fullZipToPath))
                            {
                                StreamUtils.Copy(zipStream, fsOutput, buffer);
                            }
                        }
                    }

老实说,此功能仅适用于使用sharpziplib创建的rar文件,不会打开使用winrar创建的rar

© www.soinside.com 2019 - 2024. All rights reserved.