(path string)
| 467 | } |
| 468 | |
| 469 | func countLinesInFile(path string) (int, error) { |
| 470 | file, err := os.Open(path) |
| 471 | if err != nil { |
| 472 | return 0, err |
| 473 | } |
| 474 | defer file.Close() |
| 475 | |
| 476 | buf := make([]byte, 32*1024) |
| 477 | lineCount := 0 |
| 478 | hasContent := false |
| 479 | var lastByte byte |
| 480 | |
| 481 | for { |
| 482 | n, err := file.Read(buf) |
| 483 | if n > 0 { |
| 484 | hasContent = true |
| 485 | lastByte = buf[n-1] |
| 486 | lineCount += bytes.Count(buf[:n], []byte{'\n'}) |
| 487 | } |
| 488 | if err == io.EOF { |
| 489 | break |
| 490 | } |
| 491 | if err != nil { |
| 492 | return 0, err |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if !hasContent { |
| 497 | return 0, nil |
| 498 | } |
| 499 | if lastByte != '\n' { |
| 500 | lineCount++ |
| 501 | } |
| 502 | return lineCount, nil |
| 503 | } |
| 504 | |
| 505 | func countLinesInFilesParallel(paths []string) map[string]int { |
| 506 | if len(paths) == 0 { |
no outgoing calls
no test coverage detected