add ReafFileBody and close our open file

This commit is contained in:
Aaron Bieber 2020-04-02 06:30:36 -06:00
parent 56397c4319
commit 1884f88912

View File

@ -2,6 +2,7 @@ package cromp
import ( import (
"bufio" "bufio"
"io/ioutil"
"os" "os"
"regexp" "regexp"
"time" "time"
@ -29,6 +30,11 @@ type Header struct {
UUID uuid.UUID UUID uuid.UUID
} }
// ReadFileBody grabs the entire file
func ReadFileBody(f string) ([]byte, error) {
return ioutil.ReadFile(f)
}
//ParseFileHeader grabs the header info out of an existing file //ParseFileHeader grabs the header info out of an existing file
func ParseFileHeader(f string) (*Header, error) { func ParseFileHeader(f string) (*Header, error) {
h := &Header{} h := &Header{}
@ -36,6 +42,7 @@ func ParseFileHeader(f string) (*Header, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer file.Close()
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
if err != nil { if err != nil {
return nil, err return nil, err