本文整理汇总了C#中SevenZip.SevenZipCompressor类的典型用法代码示例。如果您正苦于以下问题:C# SevenZipCompressor类的具体用法?C# SevenZipCompressor怎么用?C# SevenZipCompressor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SevenZipCompressor类属于SevenZip命名空间,在下文中一共展示了SevenZipCompressor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compress
public void Compress(string sourceFilename, string targetFilename, FileMode fileMode, OutArchiveFormat archiveFormat,
CompressionMethod compressionMethod, CompressionLevel compressionLevel, ZipEncryptionMethod zipEncryptionMethod,
string password, int bufferSize, int preallocationPercent, bool check, Dictionary<string, string> customParameters)
{
bufferSize *= this._sectorSize;
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.FastCompression = true;
compressor.ArchiveFormat = archiveFormat;
compressor.CompressionMethod = compressionMethod;
compressor.CompressionLevel = compressionLevel;
compressor.DefaultItemName = Path.GetFileName(sourceFilename);
compressor.DirectoryStructure = false;
compressor.ZipEncryptionMethod = zipEncryptionMethod;
foreach (var pair in customParameters)
{
compressor.CustomParameters[pair.Key] = pair.Value;
}
using (FileStream sourceFileStream = new FileStream(sourceFilename,
FileMode.Open, FileAccess.Read, FileShare.None, bufferSize,
Win32.FileFlagNoBuffering | FileOptions.SequentialScan))
{
using (FileStream targetFileStream = new FileStream(targetFilename,
fileMode, FileAccess.ReadWrite, FileShare.ReadWrite, 8,
FileOptions.WriteThrough | Win32.FileFlagNoBuffering))
{
this.Compress(compressor, sourceFileStream, targetFileStream,
password, preallocationPercent, check, bufferSize);
}
}
}
示例2: Zipp
public bool Zipp(IEnumerable<string> iText, string iFileName, string iPassword)
{
CheckArguments(iText, iFileName);
SevenZipCompressor sevenZipCompressor = new SevenZipCompressor()
{
DirectoryStructure = true,
EncryptHeaders = true,
DefaultItemName = "Default.txt"
};
try
{
using (var instream = new MemoryStream())
{
using (var streamwriter = new StreamWriter(instream) { AutoFlush = true })
{
iText.Apply(t => streamwriter.WriteLine(t));
instream.Position = 0;
using (Stream outstream = File.Create(iFileName))
{
sevenZipCompressor.CompressStream(instream, outstream, iPassword);
}
}
}
}
catch (Exception e)
{
Trace.WriteLine(string.Format("Problem zipping a text: {0}", e));
return false;
}
return true;
}
示例3: b_Compress_Click
private void b_Compress_Click(object sender, EventArgs e)
{
SevenZipCompressor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
SevenZipCompressor cmp = new SevenZipCompressor();
cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing);
cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_FileCompressionStarted);
cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompressionFinished);
cmp.ArchiveFormat = (OutArchiveFormat)Enum.Parse(typeof(OutArchiveFormat), cb_Format.Text);
cmp.CompressionLevel = (CompressionLevel)trb_Level.Value;
cmp.CompressionMethod = (CompressionMethod)cb_Method.SelectedIndex;
cmp.VolumeSize = chb_Volumes.Checked ? (int)nup_VolumeSize.Value : 0;
string directory = tb_CompressDirectory.Text;
string archFileName = tb_CompressOutput.Text;
bool sfxMode = chb_Sfx.Checked;
if (!sfxMode)
{
cmp.BeginCompressDirectory(directory, archFileName);
}
else
{
// Build SevenZipSharp with SFX
/*SevenZipSfx sfx = new SevenZipSfx();
using (MemoryStream ms = new MemoryStream())
{
cmp.CompressDirectory(directory, ms);
sfx.MakeSfx(ms, archFileName.Substring(0, archFileName.LastIndexOf('.')) + ".exe");
}*/
}
}
示例4: CompressionTestsVerySimple
public void CompressionTestsVerySimple(){
var tmp = new SevenZipCompressor();
//tmp.ScanOnlyWritable = true;
//tmp.CompressFiles(@"d:\Temp\arch.7z", @"d:\Temp\log.txt");
//tmp.CompressDirectory(@"c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\1033", @"D:\Temp\arch.7z");
tmp.CompressDirectory(testFold1, Path.Combine(tempFolder, TestContext.TestName + ".7z"));
}
示例5: CreateWrappedArchive
public static byte[] CreateWrappedArchive(string basePath, string[] includes, string[] excludes)
{
using (MemoryStream inStream = new MemoryStream()) {
var zipOut = new SevenZipCompressor();
zipOut.ArchiveFormat = OutArchiveFormat.Zip;
zipOut.CompressionLevel = SevenZip.CompressionLevel.None;
List<string> FileList = new List<string>(Search.FindFiles(
basePath, includes, excludes, SearchOption.AllDirectories
));
SevenZipBase.SetLibraryPath(Inits.EnsureBinaries());
zipOut.CompressFileDictionary(
FileList.ToDictionary(f => f.Replace(basePath, null), f => f),
inStream
);
inStream.Position = 0;
using (var outStream = new MemoryStream()) {
using (var LzmaStream = new LzmaEncodeStream(outStream)) {
int byt = 0;
while ((byt = inStream.ReadByte()) != -1)
LzmaStream.WriteByte((byte)byt);
}
return outStream.ToArray();
}
}
}
示例6: CompressDirectory
public static void CompressDirectory(string compressDirectory, string archFileName, OutArchiveFormat archiveFormat, CompressionLevel compressionLevel)
{
SevenZipCompressor.SetLibraryPath(LibraryPath);
SevenZipCompressor cmp = new SevenZipCompressor();
cmp.ArchiveFormat = archiveFormat;
cmp.CompressionLevel = compressionLevel;
cmp.BeginCompressDirectory(compressDirectory, archFileName);
}
示例7: GZipFiles
/// <summary>
/// Compresses files using gzip format
/// </summary>
/// <param name="files">The files.</param>
/// <param name="destination">The destination.</param>
public static void GZipFiles(string[] files, string destination)
{
SetupZlib();
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.GZip;
compressor.CompressFiles(destination, files);
}
示例8: ZipFolder
public static void ZipFolder(string archivePath, string targetDir)
{
var compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
compressor.CompressDirectory(targetDir, archivePath);
}
示例9: ZipFiles
public static void ZipFiles(string archivePath, params string[] targetFilesPath)
{
var compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
//compressor.CompressDirectory(source, output);
compressor.CompressFiles(archivePath, targetFilesPath);
}
示例10: Pack
public void Pack(string outputPath)
{
SevenZipCompressor tmp = new SevenZipCompressor();
tmp.FileCompressionStarted += new EventHandler<FileInfoEventArgs>((s, e) =>
{
Console.WriteLine(String.Format("[{0}%] {1}",
e.PercentDone, e.FileInfo.Name));
});
tmp.CompressDirectory(_targetPath, outputPath, OutArchiveFormat.SevenZip);
}
示例11: SerializationDemo
public void SerializationDemo(){
ArgumentException ex = new ArgumentException("blahblah");
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (MemoryStream ms = new MemoryStream()) {
bf.Serialize(ms, ex);
SevenZipCompressor cmpr = new SevenZipCompressor();
cmpr.CompressStream(ms, File.Create(createTempFileName()));
}
}
示例12: compress
static public void compress(string source, string outputFileName) {
if (source != null && outputFileName != null) {
SevenZipCompressor.SetLibraryPath("7z.dll");
SevenZipCompressor cmp = new SevenZipCompressor();
cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing);
cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_FileCompressionStarted);
cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompressionFinished);
cmp.ArchiveFormat = (OutArchiveFormat)Enum.Parse(typeof(OutArchiveFormat), "SevenZip");
cmp.CompressFiles(outputFileName, source);
}
}
示例13: Compress
private void Compress(string directory, string archFileName)
{
SevenZipCompressor.SetLibraryPath(AppDomain.CurrentDomain.BaseDirectory + "7z.dll");
SevenZipCompressor cmp = new SevenZipCompressor();
cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing);
cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_FileCompressionStarted);
cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompressionFinished);
cmp.ArchiveFormat = OutArchiveFormat.SevenZip;
cmp.CompressionLevel = CompressionLevel.Normal;
cmp.BeginCompressDirectory(directory, archFileName);
}
示例14: packToZip
public void packToZip(String filePathArchive, String romFolder)
{
if(!Directory.Exists(tempPath)){
Directory.CreateDirectory(tempPath);
}
archivePacker = new SevenZipCompressor(tempFolder);
archivePacker.ArchiveFormat = OutArchiveFormat.Zip;
archivePacker.BeginCompressDirectory(romFolder, filePathArchive, "");
}
示例15: Compress
private static void Compress(string savePath, string backupPath, CompressionLevel compressionLevel = CompressionLevel.None)
{
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CustomParameters.Add("mt", "on");
compressor.CompressionLevel = compressionLevel;
compressor.ScanOnlyWritable = true;
if (!Directory.Exists(backupPath))
Directory.CreateDirectory(backupPath);
compressor.CompressDirectory(savePath, (Path.Combine(backupPath, GetTimeStamp()) + ".7z"));
}