Write records bytes into both the fullOutput builder and the pending flush buffer. It triggers a flush when thresholds are reached.
(p []byte)
| 2082 | // Write records bytes into both the fullOutput builder and the pending flush |
| 2083 | // buffer. It triggers a flush when thresholds are reached. |
| 2084 | func (s *streamSink) Write(p []byte) (int, error) { |
| 2085 | s.mu.Lock() |
| 2086 | s.full.Write(p) |
| 2087 | s.pending.Write(p) |
| 2088 | shouldFlush := s.pending.Len() >= s.flushBytes || time.Since(s.lastFlush) >= s.flushEvery |
| 2089 | s.mu.Unlock() |
| 2090 | if shouldFlush { |
| 2091 | s.Flush() |
| 2092 | } |
| 2093 | return len(p), nil |
| 2094 | } |
| 2095 | |
| 2096 | // WriteString is a convenience wrapper for appending a string. |
| 2097 | func (s *streamSink) WriteString(str string) { |