I am storing a file in memory using multer, the idea is to read the buffer and check the contents of the file line by line, the moment a line does not pass validation I want to discard otherwise save to disk.
The file is a csv and I have tried createReadStream
but it fails with buffer so I have used node stream
.
The problems I am having given this implementation is that I can not return and stop anything from the Readable stream
Readable.from(buffer)
.pipe(csv())
.on('data', (data) => {
if (data.value > 10) {
return 'Stop the reading of the file I dont want it anymore'
}
})