本文整理汇总了C#中Ionic.Zlib.DeflateStream类的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream类的具体用法?C# DeflateStream怎么用?C# DeflateStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeflateStream类属于Ionic.Zlib命名空间,在下文中一共展示了DeflateStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
internal void Read()
{
try
{
using (FileStream fileStream = File.OpenRead(this.Name))
{
using (DeflateStream deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress))
{
using (BinaryReader binaryReader = new BinaryReader(deflateStream))
{
int num = (int)binaryReader.ReadByte();
for (int i = 0; i < num; i++)
{
this.AddFile(binaryReader.ReadString(), binaryReader.ReadBytes(binaryReader.ReadInt32()));
}
}
deflateStream.Dispose();
}
}
}
catch
{
this.InvalidFile = true;
}
}
示例2: Read
internal static ZipFile Read(string name, Task task, DoWorkArgs progress, ProgressChangedArgs args)
{
ZipFile zip = new ZipFile(name);
using (FileStream fileStream = File.OpenRead(name))
{
using (DeflateStream decompress = new DeflateStream(fileStream, CompressionMode.Decompress))
{
using (BinaryReader reader = new BinaryReader(decompress))
{
int count = reader.ReadByte();
for (int k = 0; k < count; k++)
{
string fileName = reader.ReadString();
if (task != null)
{
args.message = "Reading " + fileName + "...";
task.ReportProgress(progress.background, -1, args);
}
byte[] buffer = reader.ReadBytes(reader.ReadInt32());
zip[fileName] = buffer;
}
}
}
}
return zip;
}
示例3: zlibDeflate
public static void zlibDeflate(
string pathInput,
string pathOutput,
CompressionMode mode,
CompressionLevel level
)
{
using (Stream input = File.OpenRead(pathInput))
using (Stream output = File.Create(pathOutput))
using (Stream deflateStream = new DeflateStream(
mode == CompressionMode.Compress ? output : input,
mode, level, true))
{
byte[] buff = new byte[ZLIB_BUFF_SIZE];
int n = 0;
Stream toRead = mode == CompressionMode.Compress ?
input : deflateStream;
Stream toWrite = mode == CompressionMode.Compress ?
deflateStream : output;
while (0 != (n = toRead.Read(buff, 0, buff.Length)))
{
toWrite.Write(buff, 0, n);
}
deflateStream.Close();
input.Close();
output.Close();
}
}
示例4: Compress
/// <summary>
/// 지정된 데이타를 압축한다.
/// </summary>
/// <param name="input">압축할 Data</param>
/// <returns>압축된 Data</returns>
public override byte[] Compress(byte[] input) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressStartMsg);
// check input data
if(input.IsZeroLength()) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.InvalidInputDataMsg);
return CompressorTool.EmptyBytes;
}
byte[] output;
using(var outStream = new MemoryStream()) {
using(var deflate = new DeflateStream(outStream, CompressionMode.Compress, CompressionLevel.BestSpeed)) {
deflate.Write(input, 0, input.Length);
}
output = outStream.ToArray();
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
示例5: Write
internal void Write(Task task, DoWorkArgs progress, ProgressChangedArgs args)
{
using (FileStream fileStream = File.Create(this.name))
{
using (DeflateStream compress = new DeflateStream(fileStream, CompressionMode.Compress))
{
using (BinaryWriter writer = new BinaryWriter(compress))
{
writer.Write((byte)this.files.Count);
foreach (string file in this.files.Keys)
{
if (task != null)
{
args.message = "Saving " + file + "...";
task.ReportProgress(progress.background, -1, args);
}
writer.Write(file);
writer.Write(this.files[file].Length);
writer.Write(this.files[file]);
}
if (task != null)
{
args.message = "Done";
task.ReportProgress(progress.background, -1, args);
}
}
}
}
}
示例6: Compact
/// <summary>
/// Reads all log messages from the supplied file.
/// </summary>
public static void Compact(ICollection<string> inputFileNames, string outputFileName)
{
LogCollection logs = new LogCollection();
foreach (var file in inputFileNames)
{
using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (stream.ReadBoolean())
{
//Wrong File Version
break;
}
if (stream.ReadNextByte() != 1)
{
//Wrong File Version
break;
}
using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
using (var bs = new BufferedStream(zipStream, 8192))
{
while (bs.ReadBoolean())
{
var message = new LogMessage(bs);
logs.Pass1(message);
}
}
}
}
logs.Compact();
foreach (var file in inputFileNames)
{
using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
if (stream.ReadBoolean())
{
//Wrong File Version
break;
}
if (stream.ReadNextByte() != 1)
{
//Wrong File Version
break;
}
using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress, true))
using (var bs = new BufferedStream(zipStream, 8192))
{
while (bs.ReadBoolean())
{
var message = new LogMessage(bs);
logs.Pass2(message);
}
}
}
}
logs.Save(outputFileName);
}
示例7: Decompress
public byte[] Decompress(Stream inputStream)
{
using (var deflateStream = new DeflateStream(inputStream, CompressionMode.Decompress))
using (var outputStream = new MemoryStream())
{
deflateStream.WriteTo(outputStream);
return outputStream.ToArray();
}
}
示例8: DeflateEncoder
/// <summary>Deflate encoder, compatible with .NET one but with bettern compression
/// ratio (in .NET 4.0, in .NET 4.5 they are identical).</summary>
/// <param name="input">The input.</param>
/// <returns>Compressed data.</returns>
public static byte[] DeflateEncoder(byte[] input)
{
using (var ostream = new MemoryStream())
{
using (var zstream = new DeflateStream(ostream, CompressionMode.Compress))
{
zstream.Write(input, 0, input.Length);
zstream.Flush();
}
return ostream.ToArray();
}
}
示例9: CompressDeflate
public static byte[] CompressDeflate(byte[] bytes)
{
using (var ms = new MemoryStream())
{
using (var zip = new DeflateStream(ms, CompressionMode.Compress, true))
{
zip.Write(bytes, 0, bytes.Length);
}
return ms.ToArray();
}
}
示例10: DecryptAes128CbcWithGzip
private static byte[] DecryptAes128CbcWithGzip(byte[] data, byte[] key)
{
byte[] gzippedFile;
using (var cipher = new AesManaged { Mode = CipherMode.CBC, Key = key })
gzippedFile = cipher.CreateDecryptor().TransformFinalBlock(data, 0, data.Length).Skip(16).ToArray();
using (var inStream = new MemoryStream(gzippedFile))
using (var zipStream = new DeflateStream(inStream, CompressionMode.Decompress))
using (var outStream = new MemoryStream())
{
zipStream.CopyTo(outStream);
return outStream.ToArray();
}
}
示例11: CompressBuffer
public static byte[] CompressBuffer(byte[] buffer)
{
byte[] compressed;
using (var input = new MemoryStream(buffer))
using (var compressStream = new MemoryStream())
using (var compressor = new DeflateStream(compressStream, CompressionMode.Compress))
{
input.CopyTo(compressor);
compressor.Close();
compressed = compressStream.ToArray();
}
return compressed;
}
示例12: Deflate
private static byte[] Deflate(byte[] bytes)
{
if (bytes == null) return new byte[0];
using (var stream = new MemoryStream())
{
using (var compressor = new DeflateStream(stream,CompressionMode.Compress, CompressionLevel.BestSpeed))
{
compressor.Write(bytes, 0, bytes.Length);
}
return stream.ToArray();
}
}
示例13: btnApiAccess_Click
private async void btnApiAccess_Click(object sender, EventArgs e)
{
var claim = await GetClaimsAsync(UserAccessInfo.AccessToken);
var query = from info in claim where info.Item1 == UGConstants.ClaimTypes.PreferredUserName select info.Item2;
string userName = string.Empty;
if (query.Count() > 0)
userName = query.First();
var client = new HttpClient();
client.SetBearerToken(UserAccessInfo.AccessToken);
client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_ID, IoTClientId);
client.DefaultRequestHeaders.Add(UGConstants.HTTPHeaders.IOT_CLIENT_SECRET, IoTClientSecret);
client.DefaultRequestHeaders.Add(UGConstants.ClaimTypes.PreferredUserName, userName);
BaseMessage msg = new BaseMessage("", "", SSD.Framework.Exceptions.ErrorCode.IsSuccess, "");
msg.MsgJson = "{\"LocationStoreID\":1,\"ID\":1}";
StringContent queryString = new StringContent(msg.ToJson());
var response = await client.PostAsync(APIUri,queryString);
if (response.IsSuccessStatusCode)
{
string contentStr = string.Empty;
IEnumerable<string> lst;
if (response.Content.Headers != null
&& response.Content.Headers.TryGetValues(UGConstants.HTTPHeaders.CONTENT_ENCODING, out lst)
&& lst.First().ToLower() == "deflate")
{
var bj = await response.Content.ReadAsByteArrayAsync();
using (var inStream = new MemoryStream(bj))
{
using (var bigStreamsss = new DeflateStream(inStream, CompressionMode.Decompress, true))
{
contentStr = await (new StreamReader(bigStreamsss)).ReadToEndAsync();
//using (var bigStreamOut = new MemoryStream())
//{
// bigStreamsss.CopyTo(bigStreamOut);
// contentStr = Encoding.UTF8.GetString(bigStreamOut.ToArray(), 0, bigStreamOut.ToArray().Length);
//}
}
}
}
else contentStr = await response.Content.ReadAsStringAsync();
MessageBox.Show(contentStr);
}
}
示例14: DeflateByte
public static byte[] DeflateByte(byte[] content)
{
if(null==content)
{
return null;
}
using (var stream = new MemoryStream())
{
using (var compressor = new DeflateStream(stream,CompressionMode.Compress,CompressionLevel.BestSpeed))
{
compressor.Write(content,0,content.Length);
}
return stream.ToArray();
}
}
示例15: DecompressDeflate
public static byte[] DecompressDeflate(Stream input)
{
using (var decompressor = new DeflateStream(input, CompressionMode.Decompress))
{
var buffer = new byte[BufferSize];
using (var output = new MemoryStream())
{
int read;
while ((read = decompressor.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
return output.ToArray();
}
}
}