Stop stream read of fast-csv node module

482 views
Skip to first unread message

Raj Kumar

unread,
Aug 5, 2016, 10:51:10 AM8/5/16
to nodejs
How i can stop reading csv rows at some particular index using fast-csv node module? In fast-csv their is option for stream pause and resume but no option to close stream at some particular row. Following is the code :

var csvstream = CSV
.fromPath(self.fetchFilePath(fileName),{ ltrim : true, rtrim : true , headers : true , ignoreEmpty : true })
.transform(function (data){
   
Object.keys(data).forEach(function (key) {
       
var newKey       = key.trim();
       data
[newKey]     = data[key].trim();
   
});
   
return data;
})
.on("data", function(data){
     
//checking unicode char presence
     
Object.keys(data).forEach(function (key) {
       
if(data[key]){
         
var charValue   = PUNYCODE.ucs2.decode(data[key]);
          charValue
= charValue.map(function(val) {
             
if(val>126){
               
FileCleanFlag=false;
               errorData
.push(data);
             
}
         
});
       
}else{
         
FileCleanFlag=false;
       
}
     
});

     
if(!FileCleanFlag){
       
#here want to jump to end block instead of parsing next rows
     
}
})
.on('end', function (){
   
#some work on rows containing error
});

In above code how i can jump to "end" block if error occur in some row?



obsof...@gmail.com

unread,
Mar 8, 2017, 1:08:45 PM3/8/17
to nodejs
Did you find any solution ? i am facing the same issue.

Murukesh Sadasivan

unread,
Mar 12, 2017, 6:00:44 PM3/12/17
to nodejs
I havent tried it but calling this.end() might be the best bet.

Amit Sonkar

unread,
Feb 8, 2018, 9:51:54 AM2/8/18
to nodejs
I am facing this problem too, did you found any resolution ?
Reply all
Reply to author
Forward
0 new messages