public BoundaryStreamReader(string boundary, Stream baseStream, Encoding streamEncoding, int bufferLength)
        {
            if (baseStream == null)
            {
                throw new ArgumentNullException("baseStream");
            }
            if (!baseStream.CanRead)
            {
                throw new ArgumentException("baseStream must be a readable stream.");
            }

            if (!baseStream.CanSeek)
            {
                baseStream = new HistoryStream(baseStream, bufferLength);
            }

            if (bufferLength < boundary.Length + 6)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferLength),
                                                      "The buffer needs to be big enough to contain the boundary and control characters (6 bytes)");
            }

            Log        = NullLogger <IOLogSource> .Instance;
            BaseStream = baseStream;

            // by default if unspecified an encoding should be ascii
            // some people are of the opinion that utf-8 should be parsed by default
            // or that it should depend on the source page.
            // Need to test what browsers do in the wild.
            Encoding               = streamEncoding;
            _beginBoundary         = Encoding.GetBytes("\r\n--" + boundary);
            _localBuffer           = new byte[bufferLength];
            _beginBoundaryAsString = "--" + boundary;
            AtPreamble             = true;
        }
 void GivenAHistoryStreamWithBufferSize(int size) { HistoryStream = new HistoryStream(Stream, size); }
 void GivenAHistoryStream() { HistoryStream = new HistoryStream(Stream); }