javascript - Convert CSV-stream to UTF-8 in Node.js -
in advance have i'm new node.js , may did not understand yet.
i'm stuck @ moment rather obvious problem can't solve. importing csv file ftp server via node module "ftp" i'm receiving file stream convert json node module "csvtojson".
so far works wonderfully. noticed stumbled on umlaut chars german language keep crashing solution. found out have convert file stream utf8, have no idea how.
i tried tostring()
method , several other node modules didn't work.
my code looks this:
getcsvfromftp: function (profile) { init(profile); return new promise((resolve, reject) => { client.on('ready', function () { client.get(file, function (err, stream) { if (err) { return reject(err); } stream.once('close', () => { client.end(); }); csv({ trim: true, delimiter: delimiter, }).fromstream(stream, (err, result) => { if (err) { return reject(err); } return resolve(csvformatterservice.groupandformatorders(result)); }); }); }); client.connect(ftpcredentials); }); }
edit: found out problem not code, encoding of file. file western (iso 8859-1) encoded.
you can use utf8 module npm encode/decode string.
one more solution use :
convertstring = json.parse(json.stringify(convertstring));
hope helps you.
Comments
Post a Comment