本文整理汇总了C#中SevenZip.SevenZipCompressor.CompressStream方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipCompressor.CompressStream方法的具体用法?C# SevenZipCompressor.CompressStream怎么用?C# SevenZipCompressor.CompressStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipCompressor
的用法示例。
在下文中一共展示了SevenZipCompressor.CompressStream方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
}
示例2: Compress
public int Compress(PointCloudTile tile, byte[] uncompressedBuffer, int count, byte[] compressedBuffer)
{
SevenZipCompressor compressor = new SevenZipCompressor
{
CompressionMethod = SevenZip.CompressionMethod.Lzma2,
CompressionLevel = CompressionLevel.Fast
};
MemoryStream uncompressedStream = new MemoryStream(uncompressedBuffer, 0, count, false);
// custom stream is required because the position is always 32 instead of the end of the stream
MemorableMemoryStream compressedStream = new MemorableMemoryStream(compressedBuffer);
compressor.CompressStream(uncompressedStream, compressedStream);
return (int)compressedStream.MaxPosition;
}
示例3: Compress
/// <summary>
/// 压缩字节数组
/// </summary>
/// <param name="input">字节数组</param>
/// <returns>压缩后的字节数组</returns>
public static byte[] Compress(byte[] input)
{
byte[] compressed = null;
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMethod = CompressionMethod.Ppmd;
compressor.CompressionLevel = CompressionLevel.High;
using (MemoryStream ms = new MemoryStream(input))
{
using (MemoryStream outMs = new MemoryStream())
{
compressor.CompressStream(ms, outMs);
outMs.Position = 0;
compressed = new byte[outMs.Length];
outMs.Read(compressed, 0, compressed.Length);
}
}
return compressed;
}
示例4: CompressBytes
public static byte[] CompressBytes(byte[] data)
{
byte[] compressedData = null;
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMethod = CompressionMethod.Ppmd;
compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
compressor.ScanOnlyWritable = true;
compressor.DefaultItemName = "T";
using (MemoryStream msin = new MemoryStream(data))
{
using (MemoryStream msout = new MemoryStream())
{
compressor.CompressStream(msin, msout);
compressedData = msout.ToArray();
}
}
return compressedData;
}
示例5: CompressBytes
public static byte[] CompressBytes(byte[] data,
CompressionLevel CompressionLevel,
CompressionMethod CompressionMethod = CompressionMethod.Default
)
{
Inits.EnsureBinaries();
using (var inStream = new MemoryStream(data))
{
using (var outStream = new MemoryStream())
{
var compressor = new SevenZipCompressor();
compressor.CompressionLevel = (SevenZip.CompressionLevel)(int)CompressionLevel;
compressor.CompressionMethod = (SevenZip.CompressionMethod)(int)CompressionMethod;
compressor.ScanOnlyWritable = true;
compressor.CompressStream(inStream, outStream);
return outStream.ToArray();
}
}
}
示例6: HandleRequest
public override void HandleRequest(string jsonString, AjaxBase ajax)
{
CheckOtherComponentRequest request = Utility.ParseJson<CheckOtherComponentRequest>(jsonString);
CheckOtherComponentResponse response = new CheckOtherComponentResponse();
response.pass = false;
try
{
switch (request.component)
{
case 0:
SevenZipBase.SetLibraryPath(request.path);
SevenZipCompressor c = new SevenZipCompressor();
using (System.IO.MemoryStream m1 = new MemoryStream())
{
using (System.IO.MemoryStream m2 = new MemoryStream())
{
byte[] b = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
m1.Write(b, 0, b.Length);
c.CompressStream(m1, m2);
}
}
response.pass = true;
break;
default:
break;
}
}
catch (Exception)
{
}
ajax.ReturnJson(response);
}
示例7: CompressionBenchmark
private static bool CompressionBenchmark(Stream inStream, Stream outStream,
OutArchiveFormat format, CompressionMethod method,
ref LibraryFeature? features, LibraryFeature testedFeature)
{
try
{
var compr = new SevenZipCompressor { ArchiveFormat = format, CompressionMethod = method };
compr.CompressStream(inStream, outStream);
}
catch (Exception)
{
return false;
}
features |= testedFeature;
return true;
}
示例8: CompressStreamExternalTest
public void CompressStreamExternalTest(){
var tmp = new SevenZipCompressor();
tmp.CompressStream(
File.OpenRead(testFile1),
File.Create(Path.Combine(tempFolder, TestContext.TestName + ".7z"))
);
}
示例9: Compress
protected long Compress(SevenZipCompressor compressor, AlignedReadStream readStream, AlignedWriteStream writeStream,
string password)
{
using (MaxPositionStream maxWriteStream = new MaxPositionStream(writeStream))
{
if (string.IsNullOrEmpty(password))
{
compressor.CompressStream(readStream, maxWriteStream);
}
else
{
compressor.CompressStream(readStream, maxWriteStream, password);
}
return maxWriteStream.MaxPosition;
}
}
示例10: Compress
private void Compress(ref byte[] input)
{
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMethod = CompressionMethod.Lzma;
compressor.CompressionLevel = CompressionLevel.Ultra;
using (MemoryStream msin = new MemoryStream(input))
using (MemoryStream msout = new MemoryStream())
{
compressor.CompressStream(msin, msout);
msout.Position = 0;
input = new byte[msout.Length];
msout.Read(input, 0, input.Length);
}
}
示例11: 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;
}