fix: 修复 ReadLineWithParallel 当读取到文件尾时,返回的 offset 有误的问题

This commit is contained in:
kercylan98 2023-11-29 16:24:07 +08:00
parent d3ad49d11e
commit f6ea696df6
1 changed files with 5 additions and 0 deletions

View File

@ -163,6 +163,11 @@ func ReadLineWithParallel(filename string, chunkSize int64, handlerFunc func(str
_ = file.Close()
}()
fileSize, err := file.Seek(0, io.SeekEnd)
if err != nil || offset-1 >= fileSize {
return offset, err
}
chunks := FindLineChunksByOffset(file, offset, chunkSize)
var end int64
var endMutex sync.Mutex