public void Extract(ZipEntry entry, string path, bool overwrite) { if (entry.Name.EndsWith("/")) { Directory.CreateDirectory(path); return; } if (Directory.Exists(path) && !overwrite) throw new IOException(string.Format("File {0} already exists", path)); string directoryName = Path.GetDirectoryName(path); if (directoryName != null) Directory.CreateDirectory(directoryName); using (FileStream stream = File.Create(path)) { entry.Extract(stream); } File.SetCreationTime(path, entry.LastModified); File.SetLastWriteTime(path, entry.LastModified); }
public ZipEntry Add(Stream fileStream, string entryName, CompressionType compressionType) { string name = ZipEntry.NormalizeName(entryName); ZipEntry zipEntry = Find(name); if (zipEntry != null) { if (!AllowReplacingEntries) throw new Exception(string.Format("Entry {0} already exists.", entryName)); zipEntry.SetNewStream(fileStream, compressionType); _isChanged = true; } else { zipEntry = new ZipEntry(fileStream, name, compressionType); zipEntry.UseUtf8Encoding = UseUtf8Encoding; zipEntry.UseDataDescriptor = UseDataDescriptor; zipEntry.UseDataDescriptorSignature = UseDataDescriptorSignature; _entries.Add(zipEntry); if (_isNew && !AllowReplacingEntries) zipEntry.WriteEntry(_archiveStream); } _isDirty = true; return zipEntry; }