ZipEntry not saved when removing/re-adding it twice

Mar 1, 2012 at 1:16 PM

Hello List!

I have the following code:

using (var ms = new MemoryStream())
{
  this.WriteProjectConfig(this.ProjectConfig, ms); //provides some data in the memory stream
  ms.Seek(0, SeekOrigin.Begin);
  var entry = this.ZipFile[CONFIG_FILE_NAME];
  if (entry != null)
  {
    this.ZipFile.RemoveEntry(entry);
//!!    this.ZipFile.Save(pathAndFilename); //workaround, otherwise file content in zip might be zero bytes
  }
  this.ZipFile.AddEntry(CONFIG_FILE_NAME, ms);
  this.ZipFile.Save(pathAndFilename);
}

 

 

This code might become executed several times, without disposing/re-initializing the ZipFile object. The first time this runs (and the file is already in the zip, thus is being removed and re-added already on the first attempt), this works well.

 

The second++ time this code in executed it runs without exeception, but the file in the zip is of 0 bytes length, though the memory stream contained something like 10000 bytes of data.

 

But this data somehow gets lost. The workaround is to do a ZipFile.Save() after removing the entry and again after adding it.

 

I use Ionic.Zip.Reduced Version 1.9.1.8 (the latest).

 

If this a bug in the library?

 

Thanks

Karlo