diff --git a/outputproducer.go b/outputproducer.go index fa98338..3f91138 100644 --- a/outputproducer.go +++ b/outputproducer.go @@ -86,6 +86,9 @@ func (o *outputProducer) processNextRead(r io.Reader, w io.Writer, appendBuffer if _, err := w.Write(snapshot[:n]); err != nil { return fmt.Errorf("could not write: %w", err) } + } + + if n > 0 || isEOF { if err := appendBuffer(snapshot[:n], isEOF); err != nil { return fmt.Errorf("could not append buffer: %w", err) } diff --git a/outputproducer_test.go b/outputproducer_test.go index 46c0bad..5d2775e 100644 --- a/outputproducer_test.go +++ b/outputproducer_test.go @@ -37,7 +37,7 @@ func Test_outputProducer_listen(t *testing.T) { {[]byte("Three"), chunkInterval}, }, }, - []string{"One", "Two", "Three"}, + []string{"One", "Two", "Three", ""}, // Last append is EOF and should ALWAYS happen nil, }, { @@ -48,7 +48,18 @@ func Test_outputProducer_listen(t *testing.T) { {[]byte(valExceedBuff), chunkInterval}, }, }, - []string{valExceedBuff[:bufferSize], valExceedBuff[bufferSize:]}, + []string{valExceedBuff[:bufferSize], valExceedBuff[bufferSize:], ""}, // Last append is EOF and should ALWAYS happen + nil, + }, + { + "EOF should trigger an append, even if new output is empty", + func(t *testing.T) *outputProducer { return newOutputProducer(newTestOpts(nil, t)) }, + &readTester{ + []readTesterChunk{ + {[]byte("foo"), chunkInterval}, + }, + }, + []string{"foo", ""}, nil, }, }