From ca7822fea7cc1879f2452390d623de2ea0c6156b Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Tue, 8 Mar 2022 20:45:02 +0100 Subject: [PATCH] fix inital buffer size The given `maxBufferSize` can be smaller than the default value size of 4096 that is passed to `scanner.Buffer()`. This can lead to unintended behaviour. So this PR is proposing to use the minimum value of both. --- event.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/event.go b/event.go index 0d65c0e..e65a523 100644 --- a/event.go +++ b/event.go @@ -29,7 +29,8 @@ type EventStreamReader struct { // NewEventStreamReader creates an instance of EventStreamReader. func NewEventStreamReader(eventStream io.Reader, maxBufferSize int) *EventStreamReader { scanner := bufio.NewScanner(eventStream) - scanner.Buffer(make([]byte, 4096), maxBufferSize) + initBufferSize := minPosInt(4096, maxBufferSize) + scanner.Buffer(make([]byte, initBufferSize), maxBufferSize) split := func(data []byte, atEOF bool) (int, []byte, error) { if atEOF && len(data) == 0 {