begin implementing separate metadata parsing
This commit is contained in:
parent
709a2738f9
commit
35c14f09c0
6 changed files with 192 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue