Skip to content

Instantly share code, notes, and snippets.

@mlschneid
Created June 24, 2017 22:36
Show Gist options
  • Save mlschneid/29399dde82c3afa3e165093fe8be2b67 to your computer and use it in GitHub Desktop.
Save mlschneid/29399dde82c3afa3e165093fe8be2b67 to your computer and use it in GitHub Desktop.
static async Task<byte[]> ReadBytesAsync(string filePath)
{
byte[] buffer;
using(FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
if (fs.Length < Int32.MaxValue)
{
await fs.ReadAsync(buffer, 0, (int)fs.Length);
}
else
{
throw new Exception("File too large for this method");
}
}
return buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment