首页 > 代码库 > createReadStream().pipe() Callback

createReadStream().pipe() Callback

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