According to How to close a readable stream (before end)?, it is possible, you can call close()
on a readStream and it will close before end. I write a simple script to test it:
var fs = require('fs');
var l = 0
var rs = fs.createReadStream("some large file")
.on("data", function(data){
console.log("got data");
l += data.length;
if (l > 655360) {
rs.close();
console.log("close");
}
})
.on("end", function(){
console.log("shouldn't be logged");
});
output:
got data
got data
got data
got data
got data
got data
got data
got data
got data
got data
got data
close
got data
close
Though close
is printed twice, it does end the readStream.