boundary.go
func (b *boundaryReader) Read(dest []byte) (n int, err error) {
	if b.buffer.Len() >= len(dest) {
		// This read request can be satisfied entirely by the buffer
		return b.buffer.Read(dest)
	}

	peek, err := b.r.Peek(peekBufferSize)
	peekEOF := (err == io.EOF)
	if err != nil && !peekEOF && err != bufio.ErrBufferFull {
		// Unexpected error
		return 0, errors.WithStack(err)
	}
	var nCopy int
	idx, complete := locateBoundary(peek, b.nlPrefix)
	if idx != -1 {
		// Peeked boundary prefix, read until that point
		nCopy = idx
		if !complete && nCopy == 0 {
			// Incomplete boundary, move past it
			nCopy = 1
		}
	} else {
		// No boundary found, move forward a safe distance
		if nCopy = len(peek) - len(b.nlPrefix) - 1; nCopy <= 0 {
			nCopy = 0
			if peekEOF {
				// No more peek space remaining and no boundary found
				return 0, errors.WithStack(io.ErrUnexpectedEOF)
			}
		}
	}
	if nCopy > 0 {
		if _, err = io.CopyN(b.buffer, b.r, int64(nCopy)); err != nil {
			return 0, errors.WithStack(err)
		}
	}

	n, err = b.buffer.Read(dest)
	if err == io.EOF && !complete {
		// Only the buffer is empty, not the boundaryReader
		return n, nil
	}
	return n, err
}
func (b *boundaryReader) Read(dest []byte) (n int, err error) {
	if b.buffer.Len() >= len(dest) {
		// This read request can be satisfied entirely by the buffer
		return b.buffer.Read(dest)
	}

	peek, err := b.r.Peek(peekBufferSize)
	peekEOF := (err == io.EOF)
	if err != nil && !peekEOF && err != bufio.ErrBufferFull {
		// Unexpected error
		return 0, errors.WithStack(err)
	}
	var nCopy int
	idx, complete := locateBoundary(peek, b.nlPrefix)
	if idx != -1 {
		// Peeked boundary prefix, read until that point
		nCopy = idx
		if !complete && nCopy == 0 {
			// Incomplete boundary, move past it
			nCopy = 1
		}
	} else {
		// No boundary found, move forward a safe distance
		if nCopy = len(peek) - len(b.nlPrefix) - 1; nCopy <= 0 {
			nCopy = 0
			if peekEOF {
				// No more peek space remaining and no boundary found
				return 0, errors.WithStack(io.ErrUnexpectedEOF)
			}
		}
	}
	if nCopy > 0 {
		if _, err = io.CopyN(b.buffer, b.r, int64(nCopy)); err != nil {
			return 0, errors.WithStack(err)
		}
	}

	n, err = b.buffer.Read(dest)
	if err == io.EOF && !complete {
		// Only the buffer is empty, not the boundaryReader
		return n, nil
	}
	return n, err
}
// Read returns a buffer containing the content up until boundary