I have this:
type StrangBuilda struct {
strings.Builder
}
func (s StrangBuilda) Read(b []byte) (int, error) {
}
because strings.Builder doesn't implement Read() and I want to
_, err := io.Copy(l.File, b)
because when I pass a strings.Builder b ^^. It says:
Cannot use 'b' (type *strings.Builder) as the type Reader Type does not implement 'Reader' as some methods are missing: Read(p []byte) (n int, err error)
any chance we can get at the buffer of the strings.Builder or maybe have to create an entire wrapper?
We cannot get at the buffer of the
strings.Builder. We must call theString()method to access the data. That's OK because the returnedstringreferences thestrings.Builderbuffer. There is no copy or allocation.Yes, we must create a wrapper to convert a
strings.Builderto anio.ReaderThestringspackage provides us with that wrapper,strings.Reader. Here is the code we use to get anio.Readerfrom astrings.Builder: