We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
csv文件编码如下:
下面这样,可以解决乱码问题,不能 以 iso888591来解码,需要用 gbk来解码
iso888591
gbk
let filePath = './test.csv'; const rawStr = fs.readFileSync(filePath); let utf8 = iconv.decode(rawStr, 'gbk'); console.log(`after decode string:`, utf8); parse(utf8, {}, (err, out) => { if( err ){ return console.error(err); } console.log(`parse result: `, out); });
暂时还没解决,先记录下过程中相关的文章:
The text was updated successfully, but these errors were encountered:
在测试中文乱码过程中,还发现 cvs-parse 这个库,貌似有点问题,也不可能是我用的姿势不对?
cvs-parse
比如我的 cvs文件,只有 2行,像这样:
像下面这样,在 finish 事件里,获取解析出来的数据,少了最后一行
finish
const fileStream = fs.createReadStream(filePath); const rows = []; const parser = parse({ skip_empty_lines: true, }); parser.on('readable', () => { //在 finish 事件触发后,还会再触发一次readable事件,这一次,能 read 到最后一行数据 let record = null; while(record = parser.read()){ rows.push(record); } }); parser.on('error', (err) => { console.error('parser.error', err); }); //这里应该用 end 事件 parser.on('finish', () => { // 这里在最后一行数据之前触发,导致 rows 里,缺少了最后一行数据 console.log('finish rows: ', rows); }); fileStream .pipe(iconv.decodeStream('gbk')) .pipe(parser);
给官方提了一个 issue ,看看是不是我的用法不对吧
确实是用法不对,应该用 end 事件,来最终获取结果。
end
Sorry, something went wrong.
No branches or pull requests
csv文件编码如下:
下面这样,可以解决乱码问题,不能 以
iso888591
来解码,需要用gbk
来解码暂时还没解决,先记录下过程中相关的文章:
The text was updated successfully, but these errors were encountered: