begin implementing separate metadata parsing

This commit is contained in:
Daniel Fichtinger 2024-12-31 22:47:01 -05:00
parent 709a2738f9
commit 35c14f09c0
6 changed files with 192 additions and 2 deletions

View file

@ -1,6 +1,8 @@
package util
import (
"bufio"
"bytes"
"io"
"os"
)
@ -56,3 +58,25 @@ func CopyFile(inPath string, outPath string) error {
return nil
}
}
// ReadNLines reads the first N lines from a file as a single byte array
func ReadNLines(filename string, n int) ([]byte, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
var buffer bytes.Buffer
scanner := bufio.NewScanner(file)
for i := 0; i < 3 && scanner.Scan(); i++ {
buffer.Write(scanner.Bytes())
buffer.WriteByte('\n')
}
if err := scanner.Err(); err != nil {
return nil, err
}
return buffer.Bytes(), nil
}