mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 00:15:28 +08:00
22 lines
370 B
Go
22 lines
370 B
Go
package protocol
|
|
|
|
import (
|
|
"bufio"
|
|
"net/http"
|
|
)
|
|
|
|
func ScanSSELines(resp *http.Response, onLine func([]byte) bool) error {
|
|
scanner := bufio.NewScanner(resp.Body)
|
|
buf := make([]byte, 0, 64*1024)
|
|
scanner.Buffer(buf, 2*1024*1024)
|
|
for scanner.Scan() {
|
|
if !onLine(scanner.Bytes()) {
|
|
break
|
|
}
|
|
}
|
|
if err := scanner.Err(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|