MCPcopy
hub / github.com/pquerna/ffjson / WriteTo

Method WriteTo

fflib/v1/buffer.go:238–259  ·  view source on GitHub ↗

WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.

(w io.Writer)

Source from the content-addressed store, hash-verified

236// int, but it is int64 to match the io.WriterTo interface. Any error
237// encountered during the write is also returned.
238func (b *Buffer) WriteTo(w io.Writer) (n int64, err error) {
239 if b.off < len(b.buf) {
240 nBytes := b.Len()
241 m, e := w.Write(b.buf[b.off:])
242 if m > nBytes {
243 panic("bytes.Buffer.WriteTo: invalid Write count")
244 }
245 b.off += m
246 n = int64(m)
247 if e != nil {
248 return n, e
249 }
250 // all bytes should have been written, by definition of
251 // Write method in io.Writer
252 if m != nBytes {
253 return n, io.ErrShortWrite
254 }
255 }
256 // Buffer is now empty; reset.
257 b.Truncate(0)
258 return
259}
260
261// WriteByte appends the byte c to the buffer, growing the buffer as needed.
262// The returned error is always nil, but is included to match bufio.Writer's

Callers

nothing calls this directly

Calls 3

LenMethod · 0.95
TruncateMethod · 0.95
WriteMethod · 0.45

Tested by

no test coverage detected