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


C# GZipStream.WriteAsync方法代码示例

本文整理汇总了C#中System.IO.Compression.GZipStream.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.WriteAsync方法的具体用法?C# GZipStream.WriteAsync怎么用?C# GZipStream.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Compression.GZipStream的用法示例。


在下文中一共展示了GZipStream.WriteAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteAsync

 /// <summary>
 /// Compress a JSON string with base-64 encoded gzip compressed string.
 /// </summary>
 /// <param name="json">The JSON to write.</param>
 /// <param name="stream">The stream.</param>
 public static async Task WriteAsync(string json, Stream stream)
 {
     byte[] data = Encoding.UTF8.GetBytes(json);
     using (GZipStream gzip = new GZipStream(stream, CompressionMode.Compress))
     {
         await gzip.WriteAsync(data, 0, data.Length);
     }
 }
开发者ID:getsentry,项目名称:raven-csharp,代码行数:13,代码来源:GzipUtil.cs

示例2: CompressAsync

        /// <summary>
        /// Compresses a byte array.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <returns>
        /// A byte array containing the compressed data.
        /// </returns>
        public async Task<byte[]> CompressAsync(byte[] value)
        {
            MemoryStream ms = new MemoryStream();
            using (GZipStream gs = new GZipStream(ms, CompressionMode.Compress))
            {
                await gs.WriteAsync(value, 0, value.Length);
            }

            return ms.ToArray();
        }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:19,代码来源:GZipCompressor.cs

示例3: CompressAsync

        public static async Task<byte[]> CompressAsync(this byte[] data, CancellationToken cancellationToken = default(CancellationToken)) {
            byte[] compressesData;
            using (var outputStream = new MemoryStream()) {
                using (var zip = new GZipStream(outputStream, CompressionMode.Compress, true)) {
                    await zip.WriteAsync(data, 0, data.Length, cancellationToken);
                }

                await outputStream.FlushAsync(cancellationToken);
                compressesData = outputStream.ToArray();
            }

            return compressesData;
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:13,代码来源:ByteArrayExtensions.cs

示例4: CompressAsync

        public static async Task<string> CompressAsync(string input)
        {
            using (var outputStream = new MemoryStream())
            {
                using (var stream = new GZipStream(outputStream, CompressionMode.Compress))
                {
                    var bytes = Encoding.UTF8.GetBytes(input);
                    await stream.WriteAsync(bytes, 0, bytes.Length);
                }

                var output = outputStream.ToArray();
                return Convert.ToBase64String(output);
            }
        }
开发者ID:JerryBian,项目名称:CommonLibrary4Net,代码行数:14,代码来源:CompressHelper.cs

示例5: 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

示例6: AddFileAsync

		public async Task AddFileAsync(string name, Stream input, CancellationToken cancellationToken)
		{
			if (name == null) throw new ArgumentNullException(nameof(name));
			if (input == null) throw new ArgumentNullException(nameof(input));

			using (var data = new MemoryStream())
			{
				using (var zip = new GZipStream(data, CompressionMode.Compress, true))
				{
					var buffer = new byte[64 * 1024];

					int readBytes;
					while ((readBytes = await input.ReadAsync(buffer, 0, buffer.Length, cancellationToken)) != 0)
					{
						await zip.WriteAsync(buffer, 0, readBytes, cancellationToken);
					}
				}
				this.Data.Add(data.ToArray());
				this.Header.Add(name, (int)data.Length);
			}
		}
开发者ID:ppetrov,项目名称:Cchbc,代码行数:21,代码来源:ZipArchive.cs

示例7: CompressDataAsync

        private static async Task<byte[]> CompressDataAsync(byte[] data)
        {
            using (var targetStream = new MemoryStream())
            {
                using (var stream = new GZipStream(targetStream, CompressionMode.Compress))
                {
                    await stream.WriteAsync(data, 0, data.Length);
                }

                // Don't return earlier, or else the GZipStream isn't closed and we get corrupted data
                return targetStream.ToArray();
            }
        }
开发者ID:modulexcite,项目名称:Espera.Network,代码行数:13,代码来源:NetworkHelpers.cs

示例8: 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

示例9: Compress

        private static async Task<CompressionDetails> Compress(CompressionDetails compressionDetails)
        {
            byte[] data = compressionDetails.Bytes;
            using (MemoryStream compressedDataStream = new MemoryStream())
            {
                using (GZipStream streamCompressed = new GZipStream(compressedDataStream, CompressionMode.Compress))
                {
                    // write chunk in the compressed stream
                    await streamCompressed.WriteAsync(data, 0, data.Length);
                }
                byte[] compressedData = compressedDataStream.GetBuffer();
                byte[] compressedDatasize = BitConverter.GetBytes(compressedData.Length);

                CompressionDetails v = new CompressionDetails
                {
                    Bytes = compressedData,
                    ChunkSize = compressionDetails.ChunkSize,
                    Sequence = compressionDetails.Sequence,
                    CompressedDataSize = compressedDatasize
                };
                return v;
            }
        }
开发者ID:rikace,项目名称:Experiments,代码行数:23,代码来源:CompressionDataFlow.cs


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