ZipFile.Create(archivePath) creates 0 bytes archive.
Steps to reproduce
- Use
ZipFile.Create(archivePath)to create an archive. - Close created ZipFile without adding anything to it.
Expected behavior
Created archive have non-zero size (should have "End of central directory record" and be at least 22 bytes according to specification)
Actual behavior
Archive size is 0 bytes, attempt to open it with new ZipFile(archivePath) leads to ZipException "Cannot find central directory"
Version of SharpZipLib
1.1.0 also tried 1.2.0
Obtained from (only keep the relevant lines)
- Package installed using NuGet
This could be fixed by simply calling ZipFile.BeginUpdate(); and ZipFile.CommitUpdate(); in ZipFile.Create() if the file didn't already exist (or if it's size is 0).
The following code could achieve the expected result.
class CreateZipFile
{
public static void Main(string[] args)
{
using (ZipFile zip = ZipFile.Create(@".\test.zip"))
{
zip.BeginUpdate();
zip.CommitUpdate();
}
}
}
If 1.Use ZipFile.Create(archivePath) to create an archive. 2.Close created ZipFile without adding anything to it, the generated zip is decompressed by 7zip or WinRAR will prompt The archive is either in unknown format or damaged.