returns (isEOF, error)
(outputBuf *bytes.Buffer, reader io.Reader, endBytes []byte)
| 639 | |
| 640 | // returns (isEOF, error) |
| 641 | func 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 |
| 663 | func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error { |