MCPcopy
hub / github.com/Terry-Mao/goim / Write

Method Write

pkg/bufio/bufio.go:437–459  ·  view source on GitHub ↗

Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.

(p []byte)

Source from the content-addressed store, hash-verified

435// If nn < len(p), it also returns an error explaining
436// why the write is short.
437func (b *Writer) Write(p []byte) (nn int, err error) {
438 for len(p) > b.Available() && b.err == nil {
439 var n int
440 if b.Buffered() == 0 {
441 // Large write, empty buffer.
442 // Write directly from p to avoid copy.
443 n, b.err = b.wr.Write(p)
444 } else {
445 n = copy(b.buf[b.n:], p)
446 b.n += n
447 b.flush()
448 }
449 nn += n
450 p = p[n:]
451 }
452 if b.err != nil {
453 return nn, b.err
454 }
455 n := copy(b.buf[b.n:], p)
456 b.n += n
457 nn += n
458 return nn, nil
459}
460
461// WriteRaw writes the contents of p into the raw io.Writer without buffer.
462// It returns the number of bytes written.

Callers 9

TestWriteErrorsFunction · 0.95
BenchmarkWriterEmptyFunction · 0.95
WriteRawMethod · 0.95
flushMethod · 0.45
computeAcceptKeyFunction · 0.45
WriteBodyMethod · 0.45
WriteToMethod · 0.45
WriteTCPMethod · 0.45
tcpWriteProtoFunction · 0.45

Calls 3

AvailableMethod · 0.95
BufferedMethod · 0.95
flushMethod · 0.95

Tested by 2

TestWriteErrorsFunction · 0.76
BenchmarkWriterEmptyFunction · 0.76