Skip to content

Instantly share code, notes, and snippets.

@jglozano
Created May 13, 2014 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jglozano/6ff59c03842e57f181fb to your computer and use it in GitHub Desktop.
Save jglozano/6ff59c03842e57f181fb to your computer and use it in GitHub Desktop.
Reflector inferred impl of InternalReadAllBytes
[SecurityCritical]
private static byte[] InternalReadAllBytes(string path, bool checkHost)
{
byte[] buffer;
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.None, Path.GetFileName(path), false, false, checkHost))
{
int offset = 0;
long length = stream.Length;
if (length > 0x7fffffffL)
{
throw new IOException(Environment.GetResourceString("IO.IO_FileTooLong2GB"));
}
int count = (int) length;
buffer = new byte[count];
while (count > 0)
{
int num4 = stream.Read(buffer, offset, count);
if (num4 == 0)
{
__Error.EndOfFile();
}
offset += num4;
count -= num4;
}
}
return buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment