Write implements io.Writer. joins all input, splits on the separator and yields each chunk
(b []byte)
| 36 | |
| 37 | // Write implements io.Writer. joins all input, splits on the separator and yields each chunk |
| 38 | func (s *splitWriter) Write(b []byte) (int, error) { |
| 39 | n, err := s.buffer.Write(b) |
| 40 | if err != nil { |
| 41 | return n, err |
| 42 | } |
| 43 | for { |
| 44 | b = s.buffer.Bytes() |
| 45 | index := bytes.Index(b, []byte{'\n'}) |
| 46 | if index < 0 { |
| 47 | break |
| 48 | } |
| 49 | line := s.buffer.Next(index + 1) |
| 50 | s.consumer(string(line[:len(line)-1])) |
| 51 | } |
| 52 | return n, nil |
| 53 | } |
| 54 | |
| 55 | func (s *splitWriter) Close() error { |
| 56 | b := s.buffer.Bytes() |