abstractvector / node-dbf

An efficient dBase DBF file parser written in pure JavaScript
MIT License
54 stars 67 forks source link

support for CP1252 encoding #6

Open SamDecrock opened 10 years ago

SamDecrock commented 10 years ago

according to what I read on the internet, DBF doesn't use UTF-8 encoding (for characters like è, é, ü, and so on...), but the Windows CP1252 encoding.

Could you fix that so it supports CP1252 decoding?

Thx!

sin-raben commented 8 years ago

in /lib/parser

 Parser.prototype.parseField = function(field, buffer) {
      var value;
      if ((field.type === 'C')&&(this.encodingFunction)) {
          value = (this.encodingFunction(buffer)).trim();
      } else {
          value = (buffer.toString(this.encoding)).trim();
      }
      if (field.type === 'N') {
        value = parseInt(value, 10);
      } else if (field.type === 'F') {
        value = value === +value && value === (value | 0) ? parseInt(value, 10) : parseFloat(value, 10);
      }
      return value;
    };

in project

var iconv = require('iconv-lite');
....
parser.encodingFunction = function (buffer) {
    return iconv.decode(new Buffer(buffer), 'CP866'); //CP1252....
};