mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 21:29:02 +08:00
fix: keep data at EOF
This commit is contained in:
parent
a40fa68240
commit
5b722a6afe
@ -1,12 +1,12 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var newlineReg = regexp.MustCompile(`\r?\n|\r\n?`)
|
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) {
|
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||||
if atEOF && len(data) == 0 {
|
if atEOF && len(data) == 0 {
|
||||||
return 0, nil, nil
|
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 we're at EOF, we have a final, non-terminated line. Return it.
|
||||||
if atEOF {
|
if atEOF {
|
||||||
return len(data), bytes.TrimSuffix(data, []byte{'\r'}), nil
|
return len(data), data, nil
|
||||||
}
|
}
|
||||||
// Request more data.
|
// Request more data.
|
||||||
return 0, nil, nil
|
return 0, nil, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user