'use strict';

var fs = require('fs');

module.exports = function(req, res, next) {
  var path = '/tmp/' + req.params.path.replace(/\.\./g, '');

  var stream = fs.createReadStream(path).pipe(res);
  stream.on('end', function() {
    setTimeout(function() {
      fs.unlink(path);
    }, 300);

    next();
  });
};


@@ -191,16 +191,96 @@
 e(res);%0A
+  stream.on('error', function(err) %7B%0A    fs.unlink(path);%0A    next(err);%0A  %7D);%0A%0A
   stream

Handle error on stream