public void AddFile(Stream stream, string entryName) { if (stream == null) { throw new ArgumentNullException(); } if (FileInitialized() == false) { CreatePackage(); } if (String.IsNullOrEmpty(entryName)) { throw new ArgumentNullException(entryName); } stream.Seek(0, SeekOrigin.Begin); ZipArchiveStreamDataSource dataSource = new ZipArchiveStreamDataSource(stream); _zipFile.BeginUpdate(); _zipFile.Add(dataSource, entryName); _zipFile.CommitUpdate(); }
public void AddFile(string targetFile, Stream stream, string entryName) { if (File.Exists(targetFile) == false) { throw new FileNotFoundException(targetFile); } if (stream == null) { throw new ArgumentNullException(); } if (String.IsNullOrEmpty(entryName)) { throw new ArgumentNullException(entryName); } stream.Seek(0, SeekOrigin.Begin); ZipArchiveStreamDataSource dataSource = new ZipArchiveStreamDataSource(stream); ZipFile zipFile = new ZipFile(targetFile); zipFile.BeginUpdate(); zipFile.Add(dataSource, entryName); zipFile.CommitUpdate(); zipFile.Close(); }