<commit_before>'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);<commit_msg>Handle error on stream<commit_after>'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('error', function(err) {
    fs.unlink(path);
    next(err);
  });

  stream.on('end', function() {
    setTimeout(function() {
      fs.unlink(path);
    }, 300);
{'fraction_non_alphanumeric': 0.2112482853223594, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 3.478527607361963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7269546', 'n_tokens_mistral': 260, 'n_tokens_neox': 252, 'n_words': 48}