boundary.go
func locateBoundary(buf, boundaryPrefix []byte) (idx int, complete bool) {
	bpLen := len(boundaryPrefix)
	idx = bytes.Index(buf, boundaryPrefix)
	if idx == -1 {
		return
	}

	// Handle CR if present
	if idx > 0 && buf[idx-1] == '\r' {
		idx--
		bpLen++
	}

	// Fast forward to the end of the boundary prefix
	buf = buf[idx+bpLen:]
	if len(buf) == 0 {
		// Need more bytes to verify completeness
		return
	}
	if len(buf) > 1 {
		if buf[0] == '-' && buf[1] == '-' {
			return idx, true
		}
	}
	buf = bytes.TrimLeft(buf, " \t")
	if len(buf) > 0 {
		if buf[0] == '\r' || buf[0] == '\n' {
			return idx, true
		}
	}

	return
}
func locateBoundary(buf, boundaryPrefix []byte) (idx int, complete bool) {
	bpLen := len(boundaryPrefix)
	idx = bytes.Index(buf, boundaryPrefix)
	if idx == -1 {
		return
	}

	// Handle CR if present
	if idx > 0 && buf[idx-1] == '\r' {
		idx--
		bpLen++
	}

	// Fast forward to the end of the boundary prefix
	buf = buf[idx+bpLen:]
	if len(buf) == 0 {
		// Need more bytes to verify completeness
		return
	}
	if len(buf) > 1 {
		if buf[0] == '-' && buf[1] == '-' {
			return idx, true
		}
	}
	buf = bytes.TrimLeft(buf, " \t")
	if len(buf) > 0 {
		if buf[0] == '\r' || buf[0] == '\n' {
			return idx, true
		}
	}

	return
}
// Locate boundaryPrefix in buf, returning its starting idx. If complete is true, the boundary
// is terminated properly in buf, otherwise it could be false due to running out of buffer, or
// because it is not the actual boundary.
//
// Complete boundaries end in "--" or a newline