internal static FileStream InternalOpen(string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync) { return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, useAsync); }
private static byte[] InternalReadAllBytes(String path) { // bufferSize == 1 used to avoid unnecessary buffer in FileStream using (FileStream fs = FileStream.InternalOpen(path, bufferSize: 1, useAsync: false)) { long fileLength = fs.Length; if (fileLength > Int32.MaxValue) { throw new IOException(SR.IO_FileTooLong2GB); } int index = 0; int count = (int)fileLength; byte[] bytes = new byte[count]; while (count > 0) { int n = fs.Read(bytes, index, count); if (n == 0) { throw __Error.GetEndOfFile(); } index += n; count -= n; } return(bytes); } }