// Pailer reads until n lines
Pailer reads until n lines
// Pailer reads until n lines
func Pailer(data <-chan *agent.Response_ReadFile, cancel chan bool, n int, w io.Writer) error {
	writer := bufio.NewWriter(w)
	var (
		buf   bytes.Buffer
		err   error
		lines int
	)
loop:
	for fd := range data {
		_, err = buf.Write(fd.Data)
		if err != nil {
			break loop
		}
		for {
			line, err := buf.ReadBytes('\n')
			if err != nil {
				if err == io.EOF {
					buf.Write(line)
					break
				} else {
					break loop
				}
			}
			_, err = writer.Write(line)
			if err != nil {
				break loop
			}
			writer.Flush()
			lines++
			if n > 0 {
				if lines >= n {
					cancel <- true
					break loop
				}
			}
		}
		if buf.Len() > 0 {
			writer.Write(buf.Bytes())
			writer.Flush()
		}
	}
	return err
}
func Pailer ( data <- chan * agent . Response_ReadFile , cancel chan bool , n int , w io . Writer ) error { writer := bufio . NewWriter ( w ) var ( buf bytes . Buffer err error lines int ) loop : for fd := range data { _ , err = buf . Write ( fd . Data ) if err != nil { break loop } for { line , err := buf . ReadBytes ( '\n' ) if err != nil { if err == io . EOF { buf . Write ( line ) break } else { break loop } } _ , err = writer . Write ( line ) if err != nil { break loop } writer . Flush ( ) lines ++ if n > 0 { if lines >= n { cancel <- true break loop } } } if buf . Len ( ) > 0 { writer . Write ( buf . Bytes ( ) ) writer . Flush ( ) } } return err }
Pailer reads until n lines
Pailer reads until n lines