本文整理汇总了C#中System.IO.Compression.GZipStream.ReadAllBytesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.ReadAllBytesAsync方法的具体用法?C# GZipStream.ReadAllBytesAsync怎么用?C# GZipStream.ReadAllBytesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了GZipStream.ReadAllBytesAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Memory_Compress_Decompress_Async
public void Memory_Compress_Decompress_Async() {
var input = (byte[])PlainBytes.Clone();
byte[] compressed;
using(var outStream = new MemoryStream(input.Length)) {
using(var gzip = new GZipStream(outStream, CompressionMode.Compress)) {
gzip.WriteAsync(input, 0, input.Length).Wait();
}
compressed = outStream.ToArray();
Assert.IsNotNull(compressed);
Assert.IsTrue(compressed.Length > 0);
}
using(var gzip = new GZipStream(new MemoryStream(compressed), CompressionMode.Decompress)) {
var decompressed = With.TryFunctionAsync(() => gzip.ReadAllBytesAsync().Result);
Assert.IsTrue(decompressed.Length > 0);
Assert.AreEqual(PlainBytes, decompressed);
}
}
示例2: FileAsync_Compress_Decompress_Async
public void FileAsync_Compress_Decompress_Async() {
var filename = FileTool.GetTempFileName();
using(var fs = FileAsync.OpenWrite(filename))
using(var gzip = new GZipStream(fs, CompressionMode.Compress)) {
gzip.WriteAsync(PlainBytes, 0, PlainBytes.Length).Wait();
}
var fi = new FileInfo(filename);
Assert.IsTrue(fi.Exists);
Assert.IsTrue(PlainBytes.Length > fi.Length);
using(var fs = FileAsync.OpenRead(filename))
using(var gzip = new GZipStream(fs, CompressionMode.Decompress, true)) {
var output = With.TryFunctionAsync(() => gzip.ReadAllBytesAsync().Result);
Assert.AreEqual(PlainBytes.Length, output.Length);
Assert.AreEqual(PlainBytes, output);
}
fi = new FileInfo(filename);
fi.Delete();
}