mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-11-23 19:30:59 +00:00
acd7892436
Fixed some code analysis warnings. Dropped Extended Strongly Typed Resource Generator dependency. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4035615
41 lines
1017 B
C#
41 lines
1017 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Jellyfish.Library
|
|
{
|
|
public static class StreamExtensions
|
|
{
|
|
public static byte[] ReadAllBytes(this Stream stream)
|
|
{
|
|
if (stream == null)
|
|
{
|
|
throw new ArgumentNullException("stream");
|
|
}
|
|
|
|
int count = (int)stream.Length;
|
|
byte[] buffer = new byte[count];
|
|
ReadBlock(stream, buffer, 0, count);
|
|
|
|
return buffer;
|
|
}
|
|
|
|
public static int ReadBlock(this Stream stream, byte[] buffer, int offset, int count)
|
|
{
|
|
if (stream == null)
|
|
{
|
|
throw new ArgumentNullException("stream");
|
|
}
|
|
|
|
int total = 0;
|
|
int read;
|
|
do
|
|
{
|
|
total += read = stream.Read(buffer, offset + total, count - total);
|
|
}
|
|
while ((read > 0) && (total < count));
|
|
|
|
return total;
|
|
}
|
|
}
|
|
}
|