本文整理汇总了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;
}