diff --git a/stream.go b/stream.go index de2c13e..23d8a3a 100644 --- a/stream.go +++ b/stream.go @@ -177,7 +177,6 @@ func (stream *Stream) WriteEmptyObject() { func (stream *Stream) WriteMore() { stream.writeByte(',') stream.writeIndention(0) - stream.Flush() } // WriteArrayStart write [ with possible indention diff --git a/stream_test.go b/stream_test.go index 4100f22..a7018e8 100644 --- a/stream_test.go +++ b/stream_test.go @@ -63,8 +63,19 @@ func (w *NopWriter) Write(p []byte) (n int, err error) { } func Test_flush_buffer_should_stop_grow_buffer(t *testing.T) { + // Stream an array of a zillion zeros. writer := new(NopWriter) - NewEncoder(writer).Encode(make([]int, 10000000)) + stream := NewStream(ConfigDefault, writer, 512) + stream.WriteArrayStart() + for i := 0; i < 10000000; i++ { + stream.WriteInt(0) + stream.WriteMore() + stream.Flush() + } + stream.WriteInt(0) + stream.WriteArrayEnd() + + // Confirm that the buffer didn't have to grow. should := require.New(t) // 512 is the internal buffer size set in NewEncoder