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


C# DeflateStream.ReadStream方法代码示例

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


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

示例1: Decompress

        /// <summary>
        /// Decompress a byte array.
        /// </summary>
        /// <param name="source">The <see cref="Byte"/> array to decompress.</param>
        /// <param name="length">The number of bytes to read into the byte array for compression.</param>
        /// <param name="startIndex">An <see cref="Int32"/> representing the start index of the byte array.</param>
        /// <returns>A decompressed <see cref="Byte"/> array.</returns>
        public static byte[] Decompress(this byte[] source, int startIndex, int length)
        {
            const byte CompressionStrengthMask = (byte)(Bits.Bit00 | Bits.Bit01);

            // Unmask compression strength from first buffer byte
            CompressionStrength strength = (CompressionStrength)(source[startIndex] & CompressionStrengthMask);

            if (strength == CompressionStrength.NoCompression)
            {
                // No compression was applied to original buffer, return specified portion of the buffer
                return source.BlockCopy(startIndex + 1, length - 1);
            }
            else
            {
                // Create a new decompression deflater
                MemoryStream compressedData = new MemoryStream(source, startIndex + 1, length - 1);
                DeflateStream inflater = new DeflateStream(compressedData, CompressionMode.Decompress);
                int compressionDepth = (source[startIndex] & ~CompressionStrengthMask) >> 2;

                // Read uncompressed data
                byte[] destination = inflater.ReadStream();

                // When user requests muli-pass compression, there may be multiple compression passes on a buffer,
                // so we cycle through the needed uncompressions to get back to the original data
                if (strength == CompressionStrength.MultiPass && compressionDepth > 0)
                    return destination.Decompress();
                else
                    return destination;
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:37,代码来源:CompressionExtensions.cs


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