Zip entry name ends in directory separator character but contains data

微笑、不失礼 提交于 2019-12-01 10:55:05

My research shows that when you compress the files with 7-Zip utility using "Ultra" compression level, certain archives cannot be unzipped with .NET System.IO.Compression.ZipFile.ExtractToDirectory() method. The error message is: Zip entry name ends in directory separator character but contains data.

Based on my observation, this error occurs only if the following 3 conditions are met:

  1. The target archive is large - 500MB+ (Small archives seem to unzip fine).
  2. The root of the archive contains ONLY FOLDERS (if you add at least one file to the root of the archive it also unzips fine).
  3. 7-Zip Ultra compression is used.

In the end I found three solutions to this 7-Zip bug.

Solution 1: Add at least one file to the root of the archive (any dummy file or a readme.txt file).

Solution 2: Use native Windows compression utility (Select files, right-click, Send To -> Compressed folder).

Solution 3: Do not use 7-Zip Ultra compression.

All of these solutions resolved the problem for me. Pick the one that fits your project best.

The error occurs when a ZipArchive entry ends with the directory separator character '/' but has a Length != 0

You can easily find these entries with

zip.Entries.Where(o => o.FullName.EndsWith("/") && o.Length != 0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!