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


C# GZipStream.ThrowIfNull方法代码示例

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


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

示例1: ReadAllBytes

        /// <summary>
        /// Reads all bytes in the given zip stream and returns them.
        /// </summary>
        /// <param name="gzip">The zip stream that is processed.</param>
        /// <returns></returns>
        private static byte[] ReadAllBytes(GZipStream zip)
        {
            zip.ThrowIfNull("zip");

            int buffersize = 100;
            byte[] buffer = new byte[buffersize];
            int offset = 0, read = 0, size = 0;
            do
            {
                // If the buffer doesn't offer enough space left create a new array
                // with the double size. Copy the current buffer content to that array
                // and use that as new buffer.
                if (buffer.Length < size + buffersize)
                {
                    byte[] tmp = new byte[buffer.Length * 2];
                    Array.Copy(buffer, tmp, buffer.Length);
                    buffer = tmp;
                }

                // Read the net chunk of data.
                read = zip.Read(buffer, offset, buffersize);

                // Increment offset and read size.
                offset += buffersize;
                size += read;
            } while (read == buffersize); // Terminate if we read less then the buffer size.

            // Copy only that amount of data to the result that has actually been read!
            byte[] result = new byte[size];
            Array.Copy(buffer, result, size);
            return result;
        }
开发者ID:ulrakhma,项目名称:Nemo,代码行数:37,代码来源:Bytes.cs


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