此提交在文件读取功能上进行了扩展,通过在utils/file/file.go中的ReadLineWithParallel函数和FindLineChunks函数添加“start”参数,实现了从指定位置进行增量读取。此外,当扫描器遇到错误时,utils / file / file.go中的错误处理得到了改善,删除了panic表达式,而是直接返回,让函数继续处理。同时在utils/log/survey/survey.go中实现了来自utils/ file/file.go的功能,以使用新的增量读取功能替换旧功能。
36 lines
706 B
Go
36 lines
706 B
Go
package file_test
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kercylan98/minotaur/utils/file"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFilePaths(t *testing.T) {
|
|
var line int
|
|
var fileCount int
|
|
for _, path := range file.Paths(`D:\sources\minotaur`) {
|
|
if !strings.HasSuffix(path, ".go") {
|
|
continue
|
|
}
|
|
fmt.Println(path)
|
|
line += file.LineCount(path)
|
|
fileCount++
|
|
}
|
|
fmt.Println("total line:", line, "total file:", fileCount)
|
|
}
|
|
|
|
func TestNewIncrementReader(t *testing.T) {
|
|
n, _ := file.ReadLineWithParallel(`./test/t.log`, 1*1024*1024*1024, func(s string) {
|
|
t.Log(s)
|
|
})
|
|
|
|
time.Sleep(time.Second * 3)
|
|
n, _ = file.ReadLineWithParallel(`./test/t.log`, 1*1024*1024*1024, func(s string) {
|
|
t.Log(s)
|
|
}, n)
|
|
|
|
}
|