Beispiel #1
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            InnerStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options           = options;
            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            InnerStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _bufferSegmentPool    = new BufferSegmentStack(InitialSegmentPoolSize);
            _minimumReadThreshold = Math.Min(options.MinimumReadSize, options.BufferSize);
            _pool       = options.Pool == MemoryPool <byte> .Shared ? null : options.Pool;
            _bufferSize = _pool == null ? options.BufferSize : Math.Min(options.BufferSize, _pool.MaxBufferSize);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            if (readingStream is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.readingStream);
            }
            if (options is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            InnerStream        = readingStream;
            _options           = options;
            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            InnerStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.MinimumReadThreshold <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options.MinimumReadThreshold));
            }

            _minimumReadThreshold = Math.Min(options.MinimumReadThreshold, options.MinimumSegmentSize);
            _pool       = options.MemoryPool == MemoryPool <byte> .Shared ? null : options.MemoryPool;
            _bufferSize = _pool == null ? options.MinimumSegmentSize : Math.Min(options.MinimumSegmentSize, _pool.MaxBufferSize);
        }
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            _readingStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.MinimumReadThreshold <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options.MinimumReadThreshold));
            }

            _minimumSegmentSize   = options.MinimumSegmentSize;
            _minimumReadThreshold = Math.Min(options.MinimumReadThreshold, options.MinimumSegmentSize);
            _pool = options.MemoryPool;
        }
Beispiel #6
0
 /// <summary>
 /// Creates a <see cref="PipeReader"/> wrapping the specified <see cref="Stream"/>.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="readerOptions">The options.</param>
 /// <returns>A <see cref="PipeReader"/> that wraps the <see cref="Stream"/>.</returns>
 public static PipeReader Create(Stream stream, StreamPipeReaderOptions readerOptions = null)
 {
     return(new StreamPipeReader(stream, readerOptions ?? StreamPipeReaderOptions.s_default));
 }