feat: load packet logs from configured source

This commit is contained in:
zhaoyilun
2026-07-09 23:23:06 +08:00
parent 220f3f68c1
commit 28bcb94b41
10 changed files with 337 additions and 28 deletions

View File

@@ -0,0 +1,36 @@
package isphere
import (
"bufio"
"fmt"
"os"
"strings"
)
func LoadEncryptedPacketLogSourceFromFile(path string) (EncryptedPacketLogSource, error) {
trimmedPath := strings.TrimSpace(path)
if trimmedPath == "" {
return EncryptedPacketLogSource{}, fmt.Errorf("packet log file path is empty")
}
file, err := os.Open(trimmedPath)
if err != nil {
return EncryptedPacketLogSource{}, fmt.Errorf("open packet log file %q: %w", trimmedPath, err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Buffer(make([]byte, 64*1024), 16*1024*1024)
lines := []string{}
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}
lines = append(lines, line)
}
if err := scanner.Err(); err != nil {
return EncryptedPacketLogSource{}, fmt.Errorf("read packet log file %q: %w", trimmedPath, err)
}
return EncryptedPacketLogSource{Lines: lines}, nil
}