private static FileStreamStrategy ChooseStrategyCore(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize) { if (UseNet5CompatStrategy) { return(new Net5CompatFileStreamStrategy(path, mode, access, share, bufferSize == 0 ? 1 : bufferSize, options, preallocationSize)); } WindowsFileStreamStrategy strategy = (options & FileOptions.Asynchronous) != 0 ? new AsyncWindowsFileStreamStrategy(path, mode, access, share, options, preallocationSize) : new SyncWindowsFileStreamStrategy(path, mode, access, share, options, preallocationSize); return(EnableBufferingIfNeeded(strategy, bufferSize)); }
private static FileStreamStrategy ChooseStrategyCore(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { if (UseLegacyStrategy) { return(new LegacyFileStreamStrategy(path, mode, access, share, bufferSize, options)); } WindowsFileStreamStrategy strategy = (options & FileOptions.Asynchronous) != 0 ? new AsyncWindowsFileStreamStrategy(path, mode, access, share, options) : new SyncWindowsFileStreamStrategy(path, mode, access, share, options); return(EnableBufferingIfNeeded(strategy, bufferSize)); }
private static FileStreamStrategy ChooseStrategyCore(SafeFileHandle handle, FileAccess access, FileShare share, int bufferSize, bool isAsync) { if (UseLegacyStrategy) { return(new LegacyFileStreamStrategy(handle, access, bufferSize, isAsync)); } WindowsFileStreamStrategy strategy = isAsync ? new AsyncWindowsFileStreamStrategy(handle, access, share) : new SyncWindowsFileStreamStrategy(handle, access, share); return(EnableBufferingIfNeeded(strategy, bufferSize)); }
private static FileStreamStrategy ChooseStrategyCore(SafeFileHandle handle, FileAccess access, FileShare share, int bufferSize, bool isAsync) { if (UseNet5CompatStrategy) { // The .NET 5 Compat strategy does not support bufferSize == 0. // To minimize the risk of introducing bugs to it, we just pass 1 to disable the buffering. return(new Net5CompatFileStreamStrategy(handle, access, bufferSize == 0 ? 1 : bufferSize, isAsync)); } WindowsFileStreamStrategy strategy = isAsync ? new AsyncWindowsFileStreamStrategy(handle, access, share) : new SyncWindowsFileStreamStrategy(handle, access, share); return(EnableBufferingIfNeeded(strategy, bufferSize)); }
internal static FileStreamStrategy EnableBufferingIfNeeded(WindowsFileStreamStrategy strategy, int bufferSize) => bufferSize > 1 ? new BufferedFileStreamStrategy(strategy, bufferSize) : strategy;