Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encoding as an argument to constructor #8

Merged
merged 4 commits into from
Jun 26, 2014
Merged
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: 2 additions & 2 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
fs = require 'fs'

{print} = require 'sys'
{spawn} = require 'child_process'
{exec} = require 'child_process'

build = (callback) ->
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
coffee = exec 'coffee -c -o lib src'
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
Expand Down
46 changes: 22 additions & 24 deletions lib/header.js

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

61 changes: 31 additions & 30 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 @@ -15,7 +15,10 @@
"devDependencies": {
"coffee-script": ">=1.3.3"
},
"dependencies": {
"iconv-lite": ">=0.2.11"
},
"scripts": {
"prepublish": "cake build"
}
}
}
5 changes: 3 additions & 2 deletions src/parser.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{EventEmitter} = require 'events'
Header = require './header'
fs = require 'fs'
iconv = require 'iconv-lite'

class Parser extends EventEmitter

constructor: (@filename) ->
constructor: (@filename, @encoding = 'utf-8') ->

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

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

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

Expand Down