From 666b0286d51be1923e98b4d6c6a67722848a3600 Mon Sep 17 00:00:00 2001 From: Oleksandr Riznyk Date: Tue, 26 Nov 2024 12:32:03 +0200 Subject: [PATCH 1/3] Prevent multiple appending of the EOF byte at the end of the file --- dbf.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbf.go b/dbf.go index 16ef7c7..bb57c68 100644 --- a/dbf.go +++ b/dbf.go @@ -165,8 +165,10 @@ func LoadFile(fileName string) (table *DbfTable, err error) { // SaveFile dbf file. func (dt *DbfTable) SaveFile(filename string) error { - // don't forget to add dbase end of file marker which is 1Ah - dt.dataStore = appendSlice(dt.dataStore, []byte{0x1A}) + // ensure the last byte in the data store is the dBase end-of-file marker (0x1A) + if dt.dataStore[len(dt.dataStore)-1] != 0x1A { + dt.dataStore[len(dt.dataStore)-1] = 0x1A + } f, err := os.Create(filename) if err != nil { return err From 7fd73d2e7e6fa4eaed39e45466e4668d5600ca23 Mon Sep 17 00:00:00 2001 From: Oleksandr Riznyk Date: Tue, 26 Nov 2024 13:12:21 +0200 Subject: [PATCH 2/3] Update module path in go.mod --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index e74a8ee..d6c2182 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/Bowbaq/dbf +module github.com/Riznyk01/dbf -go 1.15 +go 1.22 require ( github.com/pkg/errors v0.9.1 From 0112ad623efb818b9c712d5eb1fcdbc5657aa38a Mon Sep 17 00:00:00 2001 From: Oleksandr Riznyk Date: Tue, 26 Nov 2024 16:18:02 +0200 Subject: [PATCH 3/3] Fix typo in comments --- dbf.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbf.go b/dbf.go index bb57c68..ae674cd 100644 --- a/dbf.go +++ b/dbf.go @@ -53,7 +53,7 @@ type DbfField struct { // Create a new dbase table from the scratch func New() *DbfTable { - // Create and pupulate DbaseTable struct + // Create and populate DbaseTable struct dt := new(DbfTable) // read dbase table header information @@ -96,7 +96,7 @@ func LoadFile(fileName string) (table *DbfTable, err error) { if err != nil { return nil, err } - // Create and pupulate DbaseTable struct + // Create and populate DbaseTable struct dt := new(DbfTable) dt.loading = true // set DbfTable dataStore slice that will store the complete file in memory