MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / CopyWithEndBytes

Function CopyWithEndBytes

pkg/util/utilfn/utilfn.go:641–660  ·  view source on GitHub ↗

returns (isEOF, error)

(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte)

Source from the content-addressed store, hash-verified

639
640// returns (isEOF, error)
641func CopyWithEndBytes(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte) (bool, error) {
642 buf := make([]byte, 4096)
643 for {
644 n, err := reader.Read(buf)
645 if n > 0 {
646 outputBuf.Write(buf[:n])
647 obytes := outputBuf.Bytes()
648 if bytes.HasSuffix(obytes, endBytes) {
649 outputBuf.Truncate(len(obytes) - len(endBytes))
650 return (err == io.EOF), nil
651 }
652 }
653 if err == io.EOF {
654 return true, nil
655 }
656 if err != nil {
657 return false, err
658 }
659 }
660}
661
662// does *not* close outputCh on EOF or error
663func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error {

Callers

nothing calls this directly

Calls 3

BytesMethod · 0.80
WriteMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected