node-dbf icon indicating copy to clipboard operation
node-dbf copied to clipboard

support for CP1252 encoding

Open SamDecrock opened this issue 11 years ago • 1 comments

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!

SamDecrock avatar Apr 06 '14 11:04 SamDecrock

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....
};

sin-raben avatar Jul 14 '16 06:07 sin-raben