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 }