Created
September 18, 2018 05:49
-
-
Save TheAlphamerc/a4088c15b460ee4ace7c7ec09a8105b8 to your computer and use it in GitHub Desktop.
Convert Stream to byte array C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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