mirror of
https://github.com/garraflavatra/go-fmp.git
synced 2025-07-09 16:34:05 +00:00
Final chunk reading fixes
This commit is contained in:
@ -3,7 +3,6 @@ package fmp
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -58,8 +57,10 @@ func OpenFile(path string) (*FmpFile, error) {
|
|||||||
ctx.Sectors = make([]*FmpSector, ctx.NumSectors)
|
ctx.Sectors = make([]*FmpSector, ctx.NumSectors)
|
||||||
|
|
||||||
for i := uint(0); i < ctx.NumSectors; i++ {
|
for i := uint(0); i < ctx.NumSectors; i++ {
|
||||||
println("reading sector ", i)
|
|
||||||
sector, err := ctx.readSector()
|
sector, err := ctx.readSector()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -122,7 +123,6 @@ func (ctx *FmpFile) readSector() (*FmpSector, error) {
|
|||||||
sector.Chunks = make([]*FmpChunk, 0)
|
sector.Chunks = make([]*FmpChunk, 0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
println(hex.EncodeToString(payload[0:2]))
|
|
||||||
chunk, err := ctx.readChunk(payload)
|
chunk, err := ctx.readChunk(payload)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
@ -138,7 +138,7 @@ func (ctx *FmpFile) readSector() (*FmpSector, error) {
|
|||||||
panic("chunk length not set")
|
panic("chunk length not set")
|
||||||
}
|
}
|
||||||
payload = payload[min(chunk.Length, uint32(len(payload))):]
|
payload = payload[min(chunk.Length, uint32(len(payload))):]
|
||||||
if len(payload) == 0 {
|
if len(payload) == 0 || (len(payload) == 1 && payload[0] == 0x00) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,4 @@ func TestOpenFile(t *testing.T) {
|
|||||||
if f.VersionDate.Format("2006-01-02") != "2025-01-11" {
|
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"))
|
t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
|
||||||
}
|
}
|
||||||
print(f.Sectors[0])
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user