mirror of
https://github.com/sstent/go-garminconnect.git
synced 2026-02-14 19:32:08 +00:00
with garth
This commit is contained in:
@@ -31,9 +31,9 @@ func NewFitEncoder(w io.WriteSeeker) (*FitEncoder, error) {
|
||||
|
||||
// Write header placeholder
|
||||
header := []byte{
|
||||
14, // Header size
|
||||
0x10, // Protocol version
|
||||
0x00, 0x2D, // Profile version (little endian 45)
|
||||
14, // Header size
|
||||
0x10, // Protocol version
|
||||
0x00, 0x2D, // Profile version (little endian 45)
|
||||
0x00, 0x00, 0x00, 0x00, // Data size (4 bytes, will be updated later)
|
||||
'.', 'F', 'I', 'T', // ".FIT" data type
|
||||
0x00, 0x00, // Header CRC (will be calculated later)
|
||||
@@ -102,13 +102,13 @@ func (e *FitEncoder) Close() error {
|
||||
|
||||
// Recalculate header CRC with original data
|
||||
header := []byte{
|
||||
14, // Header size
|
||||
0x10, // Protocol version
|
||||
0x00, 0x2D, // Profile version
|
||||
14, // Header size
|
||||
0x10, // Protocol version
|
||||
0x00, 0x2D, // Profile version
|
||||
dataSizeBytes[0], dataSizeBytes[1], dataSizeBytes[2], dataSizeBytes[3],
|
||||
'.', 'F', 'I', 'T', // ".FIT" data type
|
||||
}
|
||||
|
||||
|
||||
// Calculate header CRC with clean state
|
||||
e.crc = 0
|
||||
e.updateCRC(header)
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
package fit
|
||||
|
||||
// Validate performs basic validation of FIT file structure
|
||||
func Validate(data []byte) bool {
|
||||
// Minimum FIT file size is 14 bytes (header)
|
||||
if len(data) < 14 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check magic number: ".FIT"
|
||||
if string(data[8:12]) != ".FIT" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
import "fmt"
|
||||
|
||||
// MinFileSize returns the minimum size of a valid FIT file
|
||||
func MinFileSize() int {
|
||||
return 14
|
||||
// ValidateFIT validates FIT file data with basic header check
|
||||
func ValidateFIT(data []byte) error {
|
||||
// Minimal validation - check if data starts with FIT header
|
||||
if len(data) < 12 {
|
||||
return fmt.Errorf("file too small to be a valid FIT file")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user