mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
fix: keep data at EOF
This commit is contained in:
parent
a40fa68240
commit
5b722a6afe
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user