public override void Close() { // close streams if (_delegateWriter != null) { _delegateWriter.Close(); _delegateWriter = null; } if (_zipOutputStream != null) { _zipOutputStream.Close(); _zipOutputStream.Dispose(); _zipOutputStream = null; } }
public static void Add(string zipFileName, string[] entryPatterns) { string currentDirectory = Directory.GetCurrentDirectory(); Console.WriteLine("Creating {0}", zipFileName); ZipWriter writer = new ZipWriter(zipFileName); // buffer to hold temp bytes byte[] buffer = new byte[4096]; int byteCount; // add files to archive foreach (string pattern in entryPatterns) { foreach (string path in Directory.GetFiles(currentDirectory, pattern)) { string fileName = Path.GetFileName(path); Console.Write("Adding {0}", fileName); ZipEntry entry = new ZipEntry(fileName); entry.ModifiedTime = File.GetLastWriteTime(fileName); entry.Comment = "local file comment"; writer.AddEntry(entry); FileStream reader = File.OpenRead(entry.Name); while ((byteCount = reader.Read(buffer, 0, buffer.Length)) > 0) { Console.Write("."); writer.Write(buffer, 0, byteCount); } reader.Close(); Console.WriteLine(); } } writer.Close(); }