项目初始化

This commit is contained in:
2024-05-23 01:23:28 +08:00
commit f0cb950bc2
8 changed files with 173 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
package main
import (
"bytes"
"io"
)
func ReadAfterSeq(r io.Reader, size int64, seq byte, callback func([]byte)) {
var (
bytes1 []byte
pointer int64
)
for {
buf := make([]byte, 200)
n, err := r.Read(buf)
int64n := int64(n)
if err == io.EOF {
break
}
var begin int64 = -1
// 若之前指针就大于设置长度开始指向头
if pointer >= size {
begin = 0
} else if pointer+int64n >= size { // 若尾巴大于
begin = size - pointer
}
pointer += int64n
if begin == -1 {
continue
}
// 查看当前片段是否存在分隔符
for _, b := range buf[begin:n] {
// if b == 13 {
// continue
// }
if b == seq {
bytes2 := bytes.TrimSpace(bytes1)
if len(bytes2) > 0 {
callback(bytes2)
bytes1 = nil
}
continue
}
bytes1 = append(bytes1, b)
}
}
if len(bytes1) > 0 {
callback(bytes1)
}
}