Skip to content

Commit 2a1b49e

Browse files
ireestwpayne
authored andcommitted
ReadDBFOptions to skip unparseable fields
1 parent bd7d534 commit 2a1b49e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

dbf.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ type DBF struct {
8383

8484
// ReadDBFOptions are options to ReadDBF.
8585
type ReadDBFOptions struct {
86-
MaxHeaderSize int
87-
MaxRecordSize int
88-
MaxRecords int
89-
Charset string
86+
MaxHeaderSize int
87+
MaxRecordSize int
88+
MaxRecords int
89+
SkipBrokenFields bool
90+
Charset string
9091
}
9192

9293
// A DBFMemo is a DBF memo.
@@ -170,6 +171,10 @@ func ReadDBF(r io.Reader, _ int64, options *ReadDBFOptions) (*DBF, error) {
170171
fieldData := recordData[offset : offset+fieldDescriptor.Length]
171172
offset += fieldDescriptor.Length
172173
field, err := fieldDescriptor.ParseRecord(fieldData, decoder)
174+
if options.SkipBrokenFields && err != nil {
175+
field = nil
176+
err = nil
177+
}
173178
if err != nil {
174179
return nil, fmt.Errorf("field %s: %w", fieldDescriptor.Name, err)
175180
}

scanner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ func (s *ScannerDBF) Scan() (DBFRecord, error) {
758758
fieldData := recordData[offset : offset+fieldDescriptor.Length]
759759
offset += fieldDescriptor.Length
760760
field, err := fieldDescriptor.ParseRecord(fieldData, s.decoder)
761+
if s.options.SkipBrokenFields {
762+
field = nil
763+
err = nil
764+
}
761765
if err != nil {
762766
s.err = fmt.Errorf("field %s: %w", fieldDescriptor.Name, err)
763767
return nil, s.err

0 commit comments

Comments
 (0)