Skip to content

Commit 7a3c7c0

Browse files
Fixes incorrect header size when reading and writing. (#31)
Writing: Delimiter 0xD was probably ignored in the header size. Reading: Some files have a 0xD before the end of the header length is reached. Co-authored-by: Daniel Muschick <[email protected]>
1 parent b7eff14 commit 7a3c7c0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/DBFTables.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ or to retrieve columns like `dbf.fieldname`.
328328
function Table(io::IO)
329329
header = Header(io)
330330
# consider using mmap here for big dbf files
331+
332+
# Make sure data is read at the right position
333+
bytes_to_skip = header.hsize - position(io)
334+
bytes_to_skip > 0 && skip(io, bytes_to_skip)
335+
331336
data = Vector{UInt8}(undef, header.rsize * header.records)
332337
read!(io, data)
333338
strings = _create_stringarray(header, data)
@@ -464,7 +469,7 @@ function write(io::IO, tbl)
464469
fields = [FieldDescriptor(k, v) for (k,v) in pairs(getfield(dct, :values))]
465470
records = UInt32(length(first(dct)))
466471
fieldcolumns = Dict{Symbol,Int}(f.name => i for (i,f) in enumerate(fields))
467-
hsize = UInt16(length(fields) * 32 + 32)
472+
hsize = UInt16(length(fields) * 32 + 32 + 1) # +1 for the 0xD delimiter
468473
rsize = UInt16(sum(x -> x.length, fields)) + 1
469474

470475
version = 0x03

0 commit comments

Comments
 (0)