From 5b722a6afe187fcd7a3f03d9de3eaa30d6dabcc4 Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Sun, 14 Aug 2022 22:57:14 +0800 Subject: [PATCH] fix: keep data at EOF --- pkg/common/scan.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/common/scan.go b/pkg/common/scan.go index 476dbdc..64f10eb 100644 --- a/pkg/common/scan.go +++ b/pkg/common/scan.go @@ -1,12 +1,12 @@ package common import ( - "bytes" "regexp" ) var newlineReg = regexp.MustCompile(`\r?\n|\r\n?`) +// ScanLines scan lines but keep the suffix \r and \n func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) { if atEOF && len(data) == 0 { return 0, nil, nil @@ -21,7 +21,7 @@ func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) { } // If we're at EOF, we have a final, non-terminated line. Return it. if atEOF { - return len(data), bytes.TrimSuffix(data, []byte{'\r'}), nil + return len(data), data, nil } // Request more data. return 0, nil, nil