New issue
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
Stop parsing #58
Comments
Thanks for your report, I'll look at it in the next few days |
In its latest version (0.2.2), the parser use a pipe implementation when you call source = __dirname+'/test.csv';
source = fs.createReadStream(source);
source.on('end', function(){ console.log('source end') })
source.on('error', function(){ console.log('source error') })
source.on('close', function(){ console.log('source close') })
csv()
.from(source)
.on('record', function(data, index){
var date = data[0];
var vehicle = data[1];
error = date + ' | ' + vechile;
})
.on('end', function() {
console.log('csv end');
})
.on('error', function(error) {
source.destroy();
console.log('csv error');
}); Yes, error is called multiple times because destroy is an async operation but the source stream is closed before it reach the end of the file. At this point, it is your responsibility to implement the logic where the code handling the error is only called once. However, we could add an option to the parser like "stopOnError" to prevent the error listener to be called more than once. In such case, if you find it interesting, then please open a new issue (and please suggest me a better name: ). David |
Hi,
is there any way to stop the file process in case that an error ocurrs?
I've been trying to do it with the end method but it doesn't works.
I've posted a question here about it: http://stackoverflow.com/questions/13200136/stop-node-csv-parser-when-an-error-ocurrs
Thanks
The text was updated successfully, but these errors were encountered: