public void WriteItem(string name, Action <Stream> callback) { var dict = new Dictionary <string, Stream>(); var r = new RangBuffer(); dict[name] = r.R; if (first) { first = false; svc.CompressionMode = SevenZip.CompressionMode.Create; } else { svc.CompressionMode = SevenZip.CompressionMode.Append; } var task = Task.Factory.StartNew(() => { svc.CompressStreamDictionary(dict, path); }); try { callback(r.W); } finally { r.W.Dispose(); } task.Wait(); }
public static void convertZipinMemory(string zipfile) { FileStream _7zfile = File.Create(Path.GetFileNameWithoutExtension(zipfile) + ".7z"); Unzipper unzipfile = new Unzipper(zipfile); SevenZip.SevenZipCompressor _7zc = new SevenZip.SevenZipCompressor(); Dictionary <string, Stream> newentry = new Dictionary <string, Stream>(); _7zc.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip; _7zc.CompressionLevel = SevenZip.CompressionLevel.High; _7zc.CompressionMode = SevenZip.CompressionMode.Create; _7zc.PreserveDirectoryRoot = true; _7zc.DirectoryStructure = true; _7zc.FastCompression = true; foreach (string x in unzipfile.GetNextEntry()) { System.IO.MemoryStream extractedzipfileentry = new MemoryStream(); unzipfile.fz.ExtractFile(x, extractedzipfileentry); extractedzipfileentry.Position = 0; newentry.Add(x, extractedzipfileentry); } Console.WriteLine("Loaded {0} entries, beginning compression. This will take a while...", newentry.Count); _7zc.CompressStreamDictionary(newentry, _7zfile); unzipfile.Dispose(); _7zfile.Close(); Console.WriteLine("Done."); }