0

我有一个包含以下数据的文件:

8745kjhsdf CRM Natl Abc Day MC CRM Natl Jrky Day245874k001S00002000001759300.000.000.0000.0 EA 000001 001 O 50 0 2 20200323 910079105MC CRM Sandwich MC CRM Free Sandwich9901M05470001S00002000001728300.000.000.0000.0 EA 000001 001 13 20190510

读取文件后,我想将其转换为对象的 Json/Array。但无论如何我无法找到任何解决方案。

代码:

fs.createReadStream(baseFileUrl + "/data.20200409")
    //.pipe(iconv.decodeStream('ascii'))
    .pipe(es.split())
    .pipe(es.mapSync(function(line){
        console.log(line);
        // pause the readstream
        s.pause();

        lineNr += 1;

        // process line here and call s.resume() when rdy
        // function below was for logging memory usage
        //logMemoryUsage(lineNr);

        // resume the readstream, possibly from a callback
        s.resume();
    })
    .on('error', function(err){
        console.log('Error while reading file.', err);
    })
    .on('end', function(data){
      console.log(data)
        console.log('Read entire file.')
    })
);
4

0 回答 0