当前位置: 首页>>代码示例>>C#>>正文


C# GZipStream.ReadAllBytesAsync方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:20,代码来源:AsyncCompressorFixture.cs

示例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();
        }
开发者ID:debop,项目名称:NFramework,代码行数:23,代码来源:AsyncCompressorFixture.cs


注:本文中的System.IO.Compression.GZipStream.ReadAllBytesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。