Skip to content

Commit 97ef031

Browse files
author
Matt Knight
committed
Updated the README file
1 parent 0024925 commit 97ef031

File tree

1 file changed

+110
-1
lines changed

1 file changed

+110
-1
lines changed

README.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,113 @@
11
node-dbf
22
========
33

4-
An efficient dBase DBF file parser written in pure JavaScript
4+
This is an event-based dBase file parser for very efficiently reading data from *.dbf files.
5+
6+
To get started, simply install the module using npm:
7+
8+
npm install node-dbf
9+
10+
and then `require` it:
11+
12+
var Parser = require('node-dbf');
13+
14+
#Classes
15+
16+
There are two classes - the `Parser` and the `Header`. The `Parser` is the most interesting class.
17+
18+
##Parser
19+
20+
This class is the main interface for reading data from dBase files. It extends `EventEmitter` and its output is via events.
21+
22+
###new Parser(path)
23+
24+
* path `String` The full path to the .dbf file to parse
25+
26+
Creates a new Parser and attaches it to the specified filename.
27+
28+
var Parser = require('node-dbf');
29+
30+
var parser = new Parser('/path/to/my/dbase/file.dbf');
31+
32+
###parser.on(event, listener)
33+
34+
* event `String` The event name to listen for (see below for details)
35+
* listener `Function` The callback to bind to the event
36+
37+
This method is inherited from the `EventEmitter` class.
38+
39+
###parser.parse()
40+
41+
Call this method once you have bound to the events you are interested in. Although it returns the parser object (for chaining), all the dBase data is outputted via events.
42+
43+
parser.parse();
44+
45+
###Event: 'start'
46+
47+
* parser `Parser` The parser object
48+
49+
This event is emitted as soon as the `parser.parse()` method has been invoked.
50+
51+
###Event: 'header'
52+
53+
* header `Header` The header object as parsed from the dBase file
54+
55+
This event is emitted once the header has been parsed from the dBase file
56+
57+
###Event: 'record'
58+
59+
* record `Object` An object representing the record that has been found
60+
61+
The record object will have a key for each field within the record, named after the field. It is trimmed (leading and trailing) of any blank characters (dBase files use \x20 for padding).
62+
63+
In addition to the fields, the object contains two special keys:
64+
65+
* @sequenceNumber `Number` indicates the order in which it was extracted
66+
* @deleted `Boolean` whether this record has been deleted or not
67+
68+
This object may look like:
69+
70+
{
71+
"@sequenceNumber": 123,
72+
"@deleted": false,
73+
"firstName": "John",
74+
"lastName": "Smith
75+
}
76+
77+
###Event: 'end'
78+
79+
* parser `Parser` The parser object
80+
81+
This event is fired once the dBase parsing is complete and there are no more records remaining.
82+
83+
##Usage
84+
85+
The following code example illustrates a very simple usage for this module:
86+
87+
var Parser = require('node-dbf');
88+
89+
var parser = new Parser('/path/to/my/dbase/file.dbf');
90+
91+
parser.on('start', function(p) {
92+
console.log('dBase file parsing has started');
93+
});
94+
95+
parser.on('header', function(h) {
96+
console.log('dBase file header has been parsed');
97+
});
98+
99+
parser.on('record', function(record) {
100+
console.log('Name: ' + record.firstName + ' ' + record.lastName); # Name: John Smith
101+
});
102+
103+
parser.on('end', function(p) {
104+
console.log('Finished parsing the dBase file');
105+
});
106+
107+
parser.parse();
108+
109+
#TODO
110+
111+
* Write some tests
112+
* Add support for field types other than Character and Numeric
113+
* Use `fs.readStream` instead of `fs.readFile` for increased performance

0 commit comments

Comments
 (0)