Git Product home page Git Product logo

Comments (1)

sophister avatar sophister commented on August 23, 2024

在测试中文乱码过程中,还发现 cvs-parse 这个库,貌似有点问题,也不可能是我用的姿势不对?

比如我的 cvs文件,只有 2行,像这样:
image

像下面这样,在 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 事件,来最终获取结果。

from 2bugua5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.