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); }
/// <summary> /// Creates a stream that reads until it reaches the given boundary pattern. /// </summary> /// <param name="stream"></param> /// <param name="boundary"></param> public MultipartReaderStream(BufferedReadStream stream, string boundary, bool expectLeadingCrlf = true) { _innerStream = stream; _innerOffset = _innerStream.CanSeek ? _innerStream.Position : 0; if (expectLeadingCrlf) { _boundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary); } else { _boundaryBytes = Encoding.UTF8.GetBytes("--" + boundary); } _finalBoundaryLength = _boundaryBytes.Length + 2; // Include the final '--' terminator. }
public MultipartReader(string boundary, Stream stream, int bufferSize) { if (boundary == null) { throw new ArgumentNullException(nameof(boundary)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } 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); }
/// <summary> /// Creates a stream that reads until it reaches the given boundary pattern. /// </summary> /// <param name="stream"></param> /// <param name="boundary"></param> public MultipartReaderStream(BufferedReadStream stream, string boundary, bool expectLeadingCrlf = true) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (boundary == null) { throw new ArgumentNullException(nameof(boundary)); } _innerStream = stream; _innerOffset = _innerStream.CanSeek ? _innerStream.Position : 0; if (expectLeadingCrlf) { _boundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary); } else { _boundaryBytes = Encoding.UTF8.GetBytes("--" + boundary); } _finalBoundaryLength = _boundaryBytes.Length + 2; // Include the final '--' terminator. }