internal BufferedFileStreamStrategy(FileStreamStrategy strategy, int bufferSize)
        {
            Debug.Assert(bufferSize > 1, "Buffering must not be enabled for smaller buffer sizes");

            _strategy   = strategy;
            _bufferSize = bufferSize;
        }
Exemplo n.º 2
0
        internal static FileStreamStrategy ChooseStrategy(FileStream fileStream, string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize)
        {
            FileStreamStrategy strategy =
                EnableBufferingIfNeeded(ChooseStrategyCore(path, mode, access, share, options, preallocationSize), bufferSize);

            return(WrapIfDerivedType(fileStream, strategy));
        }
Exemplo n.º 3
0
        internal static FileStreamStrategy ChooseStrategy(FileStream fileStream, SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
        {
            FileStreamStrategy strategy =
                EnableBufferingIfNeeded(ChooseStrategyCore(handle, access, isAsync), bufferSize);

            return(WrapIfDerivedType(fileStream, strategy));
        }
Exemplo n.º 4
0
        internal static FileStreamStrategy ChooseStrategy(FileStream fileStream, SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
        {
            // 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.

            FileStreamStrategy strategy = UseNet5CompatStrategy ?
                                          new Net5CompatFileStreamStrategy(handle, access, bufferSize == 0 ? 1 : bufferSize, isAsync) :
                                          EnableBufferingIfNeeded(ChooseStrategyCore(handle, access, isAsync), bufferSize);

            return(WrapIfDerivedType(fileStream, strategy));
        }
 internal DerivedFileStreamStrategy(FileStream fileStream, FileStreamStrategy strategy)
 {
     _fileStream = fileStream;
     _strategy   = strategy;
 }
Exemplo n.º 6
0
 private static FileStreamStrategy WrapIfDerivedType(FileStream fileStream, FileStreamStrategy strategy)
 => fileStream.GetType() == typeof(FileStream)
         ? strategy
         : new DerivedFileStreamStrategy(fileStream, strategy);
Exemplo n.º 7
0
 private static FileStreamStrategy EnableBufferingIfNeeded(FileStreamStrategy strategy, int bufferSize)
 => bufferSize > 1 ? new BufferedFileStreamStrategy(strategy, bufferSize) : strategy;