System.IO.FileStream.InternalOpen C# (CSharp) Method

InternalOpen() static private method

static private InternalOpen ( string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync ) : FileStream
path string
bufferSize int
useAsync bool
return FileStream
        internal static FileStream InternalOpen(string path, int bufferSize = DefaultBufferSize, bool useAsync = DefaultIsAsync)
        {
            return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, useAsync);
        }

Usage Example

Example #1
0
        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);
            }
        }
All Usage Examples Of System.IO.FileStream::InternalOpen