public MultipartReader([NotNull] string boundary, [NotNull] Stream stream, int bufferSize)
 {
     if (bufferSize < boundary.Length + 8) // Size of the boundary + leading and trailing CRLF + leading and trailing '--' markers.
     {
         throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary);
     }
     _stream = new BufferedReadStream(stream, bufferSize);
     _boundary = boundary;
     // This stream will drain any preamble data and remove the first boundary marker.
     _currentStream = new MultipartReaderStream(_stream, _boundary, expectLeadingCrlf: false);
 }
 public MultipartReader([NotNull] string boundary, [NotNull] Stream stream, int bufferSize)
 {
     if (bufferSize < boundary.Length + 8) // Size of the boundary + leading and trailing CRLF + leading and trailing '--' markers.
     {
         throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary);
     }
     _stream   = new BufferedReadStream(stream, bufferSize);
     _boundary = boundary;
     // This stream will drain any preamble data and remove the first boundary marker.
     _currentStream = new MultipartReaderStream(_stream, _boundary, expectLeadingCrlf: false);
 }
 public async Task<MultipartSection> ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken())
 {
     // Drain the prior section.
     await _currentStream.DrainAsync(cancellationToken);
     // If we're at the end return null
     if (_currentStream.FinalBoundaryFound)
     {
         // There may be trailer data after the last boundary.
         await _stream.DrainAsync(cancellationToken);
         return null;
     }
     var headers = await ReadHeadersAsync(cancellationToken);
     _currentStream = new MultipartReaderStream(_stream, _boundary);
     long? baseStreamOffset = _stream.CanSeek ? (long?)_stream.Position : null;
     return new MultipartSection() { Headers = headers, Body = _currentStream, BaseStreamOffset = baseStreamOffset };
 }
        public async Task <MultipartSection> ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            // Drain the prior section.
            await _currentStream.DrainAsync(cancellationToken);

            // If we're at the end return null
            if (_currentStream.FinalBoundaryFound)
            {
                // There may be trailer data after the last boundary.
                await _stream.DrainAsync(cancellationToken);

                return(null);
            }
            var headers = await ReadHeadersAsync(cancellationToken);

            _currentStream = new MultipartReaderStream(_stream, _boundary);
            long?baseStreamOffset = _stream.CanSeek ? (long?)_stream.Position : null;

            return(new MultipartSection()
            {
                Headers = headers, Body = _currentStream, BaseStreamOffset = baseStreamOffset
            });
        }