1package testjsonl23import (4 "bufio"5 "encoding/json"6 "fmt"7 "os"8 "path/filepath"9 "strings"1011 "github.com/FelineStateMachine/puzzletea/pdfexport"12)1314func LoadRecords(path string) ([]pdfexport.JSONLRecord, error) {15 if !strings.EqualFold(filepath.Ext(path), ".jsonl") {16 return nil, fmt.Errorf("%s: expected .jsonl input", path)17 }1819 f, err := os.Open(path)20 if err != nil {21 return nil, fmt.Errorf("open input jsonl: %w", err)22 }23 defer f.Close()2425 scanner := bufio.NewScanner(f)26 scanner.Buffer(make([]byte, 0, 64*1024), 16*1024*1024)2728 records := make([]pdfexport.JSONLRecord, 0, 16)29 lineNo := 030 for scanner.Scan() {31 lineNo++32 line := strings.TrimSpace(scanner.Text())33 if line == "" {34 continue35 }3637 var record pdfexport.JSONLRecord38 if err := json.Unmarshal([]byte(line), &record); err != nil {39 return nil, fmt.Errorf("%s:%d: decode jsonl record: %w", path, lineNo, err)40 }41 if record.Schema != pdfexport.ExportSchemaV1 {42 return nil, fmt.Errorf("%s:%d: unsupported schema %q", path, lineNo, record.Schema)43 }4445 records = append(records, record)46 }47 if err := scanner.Err(); err != nil {48 return nil, fmt.Errorf("read input jsonl: %w", err)49 }50 if len(records) == 0 {51 return nil, fmt.Errorf("%s: input jsonl is empty", path)52 }5354 return records, nil55}