2017-11-02 7 views
0

Ich verarbeite eine CSV-Datei und wenn ich einen Validierungsfehler gefunden habe und möchte das Skript die Verarbeitung von Zeilenumbrüchen beenden.Wie man einen nodejs LineInputStream stoppt?

router.use(upload.single('csv')).route('/agency/:agencyId/properties/import').post(function (req, res) { 

    var stream = LineInputStream(fs.createReadStream(req.file.path, {flags: 'r'})); 
    stream.setDelimiter("\n"); 

    stream.on('line', function(line) { 
    var row = line.split(','); 
    if (row.length!=15) { 
     stream.end(); // this does not stop the processing of new lines 
     return res.status(400).json({error: 'File should have 15 columns.'}); 
    } 
    }); 

}); 

Antwort