繁体   English   中英

sharpziplib FastZip 提取 rar 错误找不到中央目录 c#

[英]sharpziplib FastZip extract rar error cannot find central directory c#

我想使用 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 文件? 感谢帮助

这里是如何提取 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

暂无
暂无

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

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