package nstd

import (
	
	
)

// CheckWriteResult checks whether or not a Write method is badly implemented.
//
// See:
//
// * https://github.com/golang/go/issues/67921
// * https://github.com/golang/go/issues/9096
func ( io.Writer,  []byte) ( int,  error) {
	,  = .Write()
	if  < 0 {
		 = 0
		if  != nil {
			 = fmt.Errorf("errBadWrite: n (%d) < 0 with additional error: %w", , )
		} else {
			 = fmt.Errorf("errBadWrite: n (%d) < 0", )
		}
	} else if  > len() {
		 = len()
		if  != nil {
			 = fmt.Errorf("errBadWrite: n (%d) > len (%d) with additional error: %w", , len(), )
		} else {
			 = fmt.Errorf("errBadWrite: n (%d) > len (%d)", , len())
		}
	} else if  < len() &&  == nil {
		 = fmt.Errorf("errBadWrite: n (%d) < len (%d) but no errors", , len())
	}
	return
}

// WriteStringWithBuffer writes a string into an [io.Writer] with a provided buffer.
// The buffer is used to avoid a string-> []byte conversion (which might allocate).
// This function is like [io.CopyBuffer] but much simpler.
func ( io.Writer,  string,  []byte) (int, error) {
	if len() == 0 {
		panic("the buffer is")
	}

	var  = 0
	for len() > 0 {
		 := [:copy(, )]

		,  := WriteWithCheck(, )
		 += len()
		if  != nil {
			return , 
		}

		 = [len():]
	}

	return , nil
}