tormoder / fit

A Go package for decoding and encoding Garmin FIT files
MIT License
243 stars 42 forks source link

Encoder: new file not readable #83

Open svergin opened 1 year ago

svergin commented 1 year ago

I've read a FIT file and modified the data. After that I wrote it to disc:

`func CreateTestFile() error { testFile := filepath.Join("c:\", "dev", "fit", "i26475458.fit") testData, err := os.ReadFile(testFile) if err != nil { return err }

r := bytes.NewReader(testData)
fitfile, err := fit.Decode(r)
if err != nil {
    return err
}

activity, err := fitfile.Activity()
if err != nil {
    return err
}

for _, rec := range activity.Records {
    rec.Speed = 0
    rec.Distance = 0
}

fo, err := os.Create("c:\\dev\\fit\\output.fit")

defer fo.Close()
w := bufio.NewWriter(fo)

err = fit.Encode(w, fitfile, binary.LittleEndian)
if err != nil {
    return err
}
return nil

} `

After that an error appears while reading it the same way as above:

error parsing file CRC: unexpected EOF

KARTOFF8xE commented 11 months ago

Same Issue right here.

I also tried to CheckIntegrity() but got the same error IF the bool-arg is set to false. Otherwise no Error.

rosvit commented 5 months ago

I ran into this issue, too. Reading newly encoded FIT file in FIT File Viewer shows that file produced by this library is 2 bytes shorter than expected:

Fatal error: FIT Runtime Error end of stream at byte 356954
There were issues decoding this file
The file is too short: Expected 356,956 bytes, got 356,954 bytes. The file was probably truncated while downloading or copying.

Decoding using fit.Decode produces same error as mentioned above:

error parsing file CRC: unexpected EOF