Skip to content

Instantly share code, notes, and snippets.

@TheAlphamerc
Created September 18, 2018 05:49
Show Gist options
  • Save TheAlphamerc/a4088c15b460ee4ace7c7ec09a8105b8 to your computer and use it in GitHub Desktop.
Save TheAlphamerc/a4088c15b460ee4ace7c7ec09a8105b8 to your computer and use it in GitHub Desktop.
Convert Stream to byte array C#
/// <summary>
/// Convert stream to byte[]
/// </summary>
/// <param name="stream"></param>
/// <returns>Byte[]</returns>
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * input.Length];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment