package nstdimport ()// 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/9096func ( io.Writer, []byte) ( int, error) { , = .Write()if < 0 { = 0if != nil { = fmt.Errorf("errBadWrite: n (%d) < 0 with additional error: %w", , ) } else { = fmt.Errorf("errBadWrite: n (%d) < 0", ) } } elseif > 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()) } } elseif < 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) {iflen() == 0 {panic("the buffer is") }var = 0forlen() > 0 { := [:copy(, )] , := WriteWithCheck(, ) += len()if != nil {return , } = [len():] }return , nil}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.