I'm working on a system where I have a Stream (which is seekable) that I am reading a ZIP file from, then am writing the modified ZIP file back to that stream. Doing so results in a corrupt file. This can be demonstrated using the following code:
using System;
using System.Collections.Generic;
using System.Text;
using Ionic.Zip;
using System.Windows.Forms;
using System.IO;
namespace ziptester
{
class Program
{
[STAThread]
static void Main(string[] args)
{
OpenFileDialog mdlg = new OpenFileDialog();
mdlg.ShowDialog();
Stream fstream = File.Open(mdlg.FileName,FileMode.Open,FileAccess.ReadWrite);
ZipFile mfile = ZipFile.Read(fstream);
mfile.UpdateEntry("test.txt", new byte[500]);
fstream.Position = 0;
mfile.SaveProgress += new EventHandler(mfile_SaveProgress);
mfile.Save(fstream);
Console.ReadKey();
}
static void mfile_SaveProgress(object sender, SaveProgressEventArgs e)
{
if (e.EventType == ZipProgressEventType.Saving_Completed)
{
Console.WriteLine("Save completed");
}
}
}
}