本文整理汇总了C#中SevenZip.SevenZipCompressor.CompressStreamDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipCompressor.CompressStreamDictionary方法的具体用法?C# SevenZipCompressor.CompressStreamDictionary怎么用?C# SevenZipCompressor.CompressStreamDictionary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipCompressor
的用法示例。
在下文中一共展示了SevenZipCompressor.CompressStreamDictionary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressArchive
public int CompressArchive(Dictionary<string, Stream> files, string outFileName)
{
// create output archive
SevenZipCompressor compressor = new SevenZipCompressor();
try
{
var dict = new Dictionary<string, Stream>();
foreach (var fileName in files.Keys)
dict.Add(fileName, files[fileName]);
compressor.CompressStreamDictionary(dict, outFileName);
return 0;
}
catch (Exception ex)
{
Logger.Logwrite(ex.Message);
Console.Error.WriteLine("Error: Could not create output archive: " + outFileName);
Console.Error.WriteLine("\t" + ex.Message);
return 1;
}
}
示例2: BackupFiles
//.........这里部分代码省略.........
case 2:
sevenZip.CompressionLevel = CompressionLevel.Fast;
break;
case 3:
sevenZip.CompressionLevel = CompressionLevel.Low;
break;
case 4:
sevenZip.CompressionLevel = CompressionLevel.Low;
break;
case 5:
sevenZip.CompressionLevel = CompressionLevel.Low;
break;
case 6:
sevenZip.CompressionLevel = CompressionLevel.Normal;
break;
case 7:
sevenZip.CompressionLevel = CompressionLevel.High;
break;
case 8:
sevenZip.CompressionLevel = CompressionLevel.High;
break;
case 9:
sevenZip.CompressionLevel = CompressionLevel.Ultra;
break;
}
if (BackupProgress != null)
{
sevenZip.FileCompressionStarted += (sender, e) =>
{
var ebp = new BackupProgressEventArgs()
{
AcrhiveFileName = e.FileName,
Action = EventAction.StartingArchive
};
sevenZipCurrentFile = e.FileName;
Report7ZipProgress(component, volumeMap, ebp);
if (cancel)
{
e.Cancel = true;
}
};
sevenZip.FileCompressionFinished += (sender, e) =>
{
var ebp = new BackupProgressEventArgs()
{
AcrhiveFileName = sevenZipCurrentFile,
Action = EventAction.ArchiveDone
};
sevenZipCurrentFile = String.Empty;
Report7ZipProgress(component, volumeMap, ebp);
};
sevenZip.Compressing += (sender, e) =>
{
var ebp = new BackupProgressEventArgs()
{
AcrhiveFileName = sevenZipCurrentFile,
Action = EventAction.PercentProgress,
CurrentEntry = sevenZipCurrentFile,
PercentDone = e.PercentDone
};
Report7ZipProgress(component, volumeMap, ebp);
if (cancel)
{
e.Cancel = true;
}
};
}
if (string.IsNullOrEmpty(options.Password))
sevenZip.CompressStreamDictionary(files, vmBackupPath);
else
sevenZip.CompressStreamDictionary(files, vmBackupPath, options.Password);
if (cancel)
{
if (File.Exists(vmBackupPath))
{
File.Delete(vmBackupPath);
}
throw new BackupCancelledException();
}
}
}
finally
{
// Make sure that all streams are closed
foreach (var s in streams)
s.Close();
}
}
示例3: Write
public void Write(CloudFile cloudFile, Stream stream, OnProgress onProgress)
{
logger.DebugFormat("7zip, start writing [{0}]", cloudFile.FullName());
cloudFile.Format = CloudFileFormat.SevenZip;
//cloudFile.Fingerprint = HashHelper.MD5(cloudFile.Fingerprint + password);
stream.Position = 0;
// set the name into the package
Dictionary<String, Stream> dir = new Dictionary<string, Stream>();
dir[cloudFile.Name] = stream;
// drive low level provider to write data
using (MemoryStream compressedStream = new MemoryStream())
{
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.Compressing += new EventHandler<ProgressEventArgs>(
(o, p) => {
onProgress(cloudFile, ProcessTypes.Compress, (p.PercentDone * stream.Length / 100), stream.Length);
logger.InfoFormat("Compressing [{0}], [{1}% of {2}MB]", cloudFile.Name, p.PercentDone, (int)(stream.Length / 1024 / 1024));
});
compressor.CompressStreamDictionary(dir, compressedStream, password);
compressedStream.Position = 0;
cloudFile.MD5 = cloudFile.Fingerprint;
cloudFile.Fingerprint = HashHelper.MD5(cloudFile.Fingerprint+password);
provider.Write(cloudFile, compressedStream, onProgress);
}
logger.DebugFormat("7zip, finish writing [{0}]", cloudFile.FullName());
}