|
|
@@ -56,7 +56,11 @@ func getFileContent(filename string, nLines int) string {
|
|
|
if err != nil {
|
|
|
return "file not found"
|
|
|
}
|
|
|
+ // bufio.Scan默认缓冲区大小只有40000, 如果不设置缓存区, 遇到数据大于40000的将返回false
|
|
|
+ const maxCapacity = 512 * 1024
|
|
|
+ buf := make([]byte, maxCapacity)
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
+ scanner.Buffer(buf, maxCapacity)
|
|
|
total := 0
|
|
|
for scanner.Scan() {
|
|
|
total++
|
|
|
@@ -69,6 +73,7 @@ func getFileContent(filename string, nLines int) string {
|
|
|
file.Seek(0, 0)
|
|
|
index := 0
|
|
|
s := bufio.NewScanner(file)
|
|
|
+ s.Buffer(buf, maxCapacity)
|
|
|
for s.Scan() {
|
|
|
if index >= readPos {
|
|
|
txt += s.Text() + "<br>"
|