github.com/drone/runner-go@v1.12.0/livelog/copy.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package livelog
     6  
     7  import (
     8  	"bufio"
     9  	"io"
    10  )
    11  
    12  // Copy copies from src to dst and removes until either EOF
    13  // is reached on src or an error occurs.
    14  func Copy(dst io.Writer, src io.ReadCloser) error {
    15  	r := bufio.NewReader(src)
    16  	for {
    17  		bytes, err := r.ReadBytes('\n')
    18  		if _, err := dst.Write(bytes); err != nil {
    19  			return err
    20  		}
    21  		if err != nil {
    22  			if err != io.EOF {
    23  				return err
    24  			}
    25  			return nil
    26  		}
    27  	}
    28  }