Thursday, 28 June 2018

decoding array of utf8 strings inside a stream Ask Question

I faced a weird problem today after trying to decode a utf8 formatted string. It's being fetched through stream as an array of strings but formatted in utf8 somehow (I'm using fast-csv). However as you can see in the console if I log it directly it shows the correct version but when it's inside an object literal it's back to utf8 encoded version. var stream = fs .createReadStream(__dirname + '/my.csv') .pipe(csv({ ignoreEmpty: true })) .on('data', data => { console.log(data[0]) // prints farren@rogers.com console.log({ firstName: data[0] }) // prints { firstName: '\u0000f\u0000a\u0000r\u0000r\u0000e\u0000n\u0000@\u0000r\u0000o\u0000g\u0000e\u0000r\u0000s\u0000.\u0000c\u0000o\u0000m\u0000' } }) Any solution or explanations are appreciated.Edit: even after decoding using utf8.js and then pass it in the object literal, I still encounter the same problem.

Submitted June 28, 2018 at 03:09PM by sourcesoft

No comments:

Post a Comment