MCPcopy Index your code
hub / github.com/google/gvisor / ReadToWriter

Method ReadToWriter

pkg/buffer/buffer.go:536–551  ·  view source on GitHub ↗

ReadToWriter reads from the buffer into an io.Writer. N.B. This does not consume the bytes read. TrimFront should be called appropriately after this call in order to do so.

(w io.Writer, count int64)

Source from the content-addressed store, hash-verified

534// N.B. This does not consume the bytes read. TrimFront should
535// be called appropriately after this call in order to do so.
536func (b *Buffer) ReadToWriter(w io.Writer, count int64) (int64, error) {
537 bytesLeft := int(count)
538 for v := b.data.Front(); v != nil && bytesLeft > 0; v = v.Next() {
539 view := v.Clone()
540 if view.Size() > bytesLeft {
541 view.CapLength(bytesLeft)
542 }
543 n, err := io.Copy(w, view)
544 bytesLeft -= int(n)
545 view.Release()
546 if err != nil {
547 return count - int64(bytesLeft), err
548 }
549 }
550 return count - int64(bytesLeft), nil
551}
552
553// read implements the io.Reader interface. This method is used by BufferReader
554// to consume its underlying buffer. To perform io operations on buffers

Callers 2

BenchmarkWriteReadFunction · 0.95
TestBufferFunction · 0.95

Calls 7

NextMethod · 0.65
CloneMethod · 0.65
SizeMethod · 0.65
CopyMethod · 0.65
ReleaseMethod · 0.65
FrontMethod · 0.45
CapLengthMethod · 0.45

Tested by 2

BenchmarkWriteReadFunction · 0.76
TestBufferFunction · 0.76