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?