const stream = fs.createReadStream(‘<filepath>/example.pdf‘, {bufferSize: 64 * 1024})
stream.pipe(res);
let had_error = false;
stream.on(‘error‘, function(err){
had_error = true;
});
stream.on(‘close‘, function(){
if (!had_error) fs.unlink(‘<filepath>/example.pdf‘);
});
createReadStream().pipe() Callback
原文:http://www.cnblogs.com/yudis/p/7121924.html