Skip to content

Commit

Permalink
add: read raw data track on hfe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Le Saux committed Oct 18, 2023
1 parent e680ddb commit 4e8f52d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions hfe/hfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type PicTrack struct {
type HFE struct {
Header PicFileFormatHeader
Tracks []PicTrack
Data [][]byte
Size uint
}

Expand Down Expand Up @@ -162,16 +163,32 @@ func Read(r io.Reader) (HFE, error) {
}

h.Tracks = make([]PicTrack, h.Header.NbTracks)
h.Data = make([][]byte, h.Header.NbTracks)
for i := 0; i < int(h.Header.NbTracks); i++ {
err := binary.Read(rb, binary.LittleEndian, &h.Tracks[i])
if err != nil {
return HFE{}, err
}
h.Tracks[i].Offset *= 512
}
for i := 0; i < int(h.Header.NbTracks); i++ {
h.Data[i], err = h.ReadTrack(h.Tracks[i], rb)
if err != nil {
return HFE{}, err
}
}
return h, nil
}

func (h HFE) ReadTrack(tr int, r io.Reader) {

func (h HFE) ReadTrack(pt PicTrack, r Reader) ([]byte, error) {
_, err := r.Seek(int64(pt.Offset), io.SeekStart)
if err != nil {
return []byte{}, err
}
data := make([]byte, pt.TrackLen)
err = binary.Read(r, binary.LittleEndian, &data)
if err != nil {
return []byte{}, err
}
return data, nil
}

0 comments on commit 4e8f52d

Please sign in to comment.