Skip to content

Commit

Permalink
Fix test again
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdowns committed Jan 2, 2023
1 parent 4776893 commit 835bda7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/lib/Shapefile/Shapefile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe('Shapefile', () => {
test('dbf', () => {
const dbf = USA_adm1.parse('dbf', { properties: true })
expect(dbf.header.version).toBe(DbaseVersion.Level5) // 3
console.log(dbf.header.lastUpdated)
expect(dbf.header.lastUpdated.toISOString()).toBe('2015-08-11T00:00:00.000Z')
expect(dbf.header.numberOfRecords).toBe(52)
expect(dbf.header.numberOfBytesInHeader).toBe(321)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Shapefile/Shapefile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Shapefile {
case 'shx':
return parsers.shx(this.contents.shx.buffer)
case 'dbf':
return parsers.dbf(this.contents.dbf.buffer, ...args)
return parsers.dbf(this.contents.dbf.buffer, args[0])
}

return undefined
Expand Down
12 changes: 6 additions & 6 deletions src/lib/Shapefile/parsers/dbf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DbfOptions {
properties: boolean
}

function dbf(arrayBuffer: ArrayBuffer, properties = true): Dbase<DbaseVersion, typeof properties> {
function dbf(arrayBuffer: ArrayBuffer, options: DbfOptions): Dbase<DbaseVersion, typeof options.properties> {
const array = new Uint8Array(arrayBuffer)
const dv = new DataView(arrayBuffer)

Expand Down Expand Up @@ -43,15 +43,15 @@ function dbf(arrayBuffer: ArrayBuffer, properties = true): Dbase<DbaseVersion, t
: 68,
arrayBuffer.byteLength)),
header,
properties)
options)

return {
header,
fields
}
}

function getFields(array: Uint8Array, header: DbaseHeader<DbaseVersion>, properties: boolean): Array<DbaseField<typeof header.version, typeof properties>> {
function getFields(array: Uint8Array, header: DbaseHeader<DbaseVersion>, options: DbfOptions): Array<DbaseField<typeof header.version, typeof options.properties>> {
let size: number
switch (header.version) {
case DbaseVersion.Level5:
Expand All @@ -62,20 +62,20 @@ function getFields(array: Uint8Array, header: DbaseHeader<DbaseVersion>, propert
break
}

const fields: Array<DbaseField<typeof header.version, typeof properties>> = []
const fields: Array<DbaseField<typeof header.version, typeof options.properties>> = []
let bp = 0
let terminated = false
do {
const terminator = array[bp]
if (terminator === 0x0D) terminated = true
else {
fields.push(getField(array.slice(bp, bp + size), header.version, properties))
fields.push(getField(array.slice(bp, bp + size), header.version, options.properties))
bp += size
}
} while (!terminated)
bp += 1

if (properties === true) {
if (options.properties === true) {
do {
for (let i = 0; i < fields.length; i++) {
const valueRaw = Buffer.from(array.slice(bp, bp + fields[i].length)).toString('utf-8').trim()
Expand Down

0 comments on commit 835bda7

Please sign in to comment.