DBFFile
Summary
Read and write .dbf (dBase III and Visual FoxPro) files in Node.js:
- Supported field types:
C
(string)N
(numeric)F
(float)I
(integer)L
(logical)D
(date)T
(datetime)B
(double)M
(memo) Note: memo support is experimental/partial, with the following limitations:- read-only (can't create/write DBF files with memo fields)
- dBase III (version 0x83) and dBase IV (version 0x8b)
.dbt
memo files only
- Can open an existing .dbf file
- Can access all field descriptors
- Can access total record count
- Can read records in arbitrary-sized batches
- Supports very large files
- Can create a new .dbf file
- Can use field descriptors from a user-specified object of from another instance
- Can append records to an existing .dbf file
- Supports very large files
- Can specify character encodings either per-file or per-field.
- the default encoding is
'ISO-8859-1'
(also known as latin 1) - example per-file encoding:
DBFFile.open(<path>, {encoding: 'EUC-JP'})
- example per-field encoding:
DBFFile.open(<path>, {encoding: {default: 'latin1', FIELD_XYZ: 'EUC-JP'}})
- supported encodings are listed here.
- the default encoding is
- All operations are asynchronous and return a promise
Installation
npm install dbffile
or yarn add dbffile
Example: reading a .dbf file
; { let dbf = await DBFFile; console; console; let records = await dbf; for let record of records console;}
Example: writing a .dbf file
; { let fieldDescriptors = name: 'fname' type: 'C' size: 255 name: 'lname' type: 'C' size: 255 ; let records = fname: 'Joe' lname: 'Bloggs' fname: 'Mary' lname: 'Smith' ; let dbf = await DBFFile; console; await dbf; console;}
API
The module exports the DBFFile
class, which has the following shape:
/** Represents a DBF file. */ /** Metadata describing a single field in a DBF file. */ /** Options that may be passed to `DBFFile.open` and `DBFFile.create`. */