1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 04:25:11 +00:00

Final chunk reading fixes

This commit is contained in:
2025-06-12 09:22:32 +02:00
parent 659ad61300
commit 717efdf9fa
2 changed files with 4 additions and 5 deletions

View File

@ -3,7 +3,6 @@ package fmp
import (
"bytes"
"encoding/binary"
"encoding/hex"
"io"
"os"
"time"
@ -58,8 +57,10 @@ func OpenFile(path string) (*FmpFile, error) {
ctx.Sectors = make([]*FmpSector, ctx.NumSectors)
for i := uint(0); i < ctx.NumSectors; i++ {
println("reading sector ", i)
sector, err := ctx.readSector()
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
@ -122,7 +123,6 @@ func (ctx *FmpFile) readSector() (*FmpSector, error) {
sector.Chunks = make([]*FmpChunk, 0)
for {
println(hex.EncodeToString(payload[0:2]))
chunk, err := ctx.readChunk(payload)
if err == io.EOF {
break
@ -138,7 +138,7 @@ func (ctx *FmpFile) readSector() (*FmpSector, error) {
panic("chunk length not set")
}
payload = payload[min(chunk.Length, uint32(len(payload))):]
if len(payload) == 0 {
if len(payload) == 0 || (len(payload) == 1 && payload[0] == 0x00) {
break
}
}

View File

@ -19,5 +19,4 @@ func TestOpenFile(t *testing.T) {
if f.VersionDate.Format("2006-01-02") != "2025-01-11" {
t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
}
print(f.Sectors[0])
}