Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ In addition to the fields, the object contains two special keys:
* @sequenceNumber `Number` indicates the order in which it was extracted
* @deleted `Boolean` whether this record has been deleted or not

Each field is parsed using the `utf-8` encoding. If you want a different encoding, you should initialize the Parser with that encoding:

new Parser('/path/to/my/dbase/file.dbf', 'win1252');

This object may look like:

{
Expand Down
67 changes: 36 additions & 31 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-dbf",
"version": "0.1.0",
"version": "0.1.1",
"description": "An efficient dBase DBF file parser written in pure JavaScript",
"main": "./lib/parser.js",
"repository": {
Expand All @@ -17,5 +17,8 @@
},
"scripts": {
"prepublish": "cake build"
},
"dependencies": {
"iconv-lite": "~0.2.11"
}
}
}
9 changes: 7 additions & 2 deletions src/parser.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{EventEmitter} = require 'events'
Header = require './header'
fs = require 'fs'
iconv = require 'iconv-lite'


class Parser extends EventEmitter

constructor: (@filename) ->
constructor: (@filename, @encoding) ->

parse: =>
@emit 'start', @
Expand Down Expand Up @@ -41,7 +43,10 @@ class Parser extends EventEmitter
return record

parseField: (field, buffer) =>
value = (buffer.toString 'utf-8').replace /^\x20+|\x20+$/g, ''
encoding = 'utf-8'
encoding = @encoding if @encoding

value = iconv.decode(buffer, encoding).replace /^\x20+|\x20+$/g, ''

if field.type is 'N' then value = parseInt value, 10

Expand Down