Read entire stream into a byte array
using System;
using System.IO;
using System.Text;
public static class CompressionUtility
{
/// <summary>
/// Read entire stream into a byte array
/// </summary>
/// <param name="stream">Stream to read</param>
/// <returns>Byte array</returns>
public static byte[] ReadFullStream(Stream stream)
{
byte[] buffer = new byte[32768];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
Related examples in the same category