<commit_before>var fs = require('fs');
var os = require('os');
var Batch = require('batch');
var express = require('express');
var router = express.Router();
var config = require('./../lib/config');
var utils = require('./../lib/utils');
var multiparty = require('multiparty');

/* GET sounds configuration */
router.get('/', function (req, res) {
  res.json(config.get('sounds'));
});

/* Save configuration. */
router.put('/', function (req, res) {
  var payload = req.body;
  config.merge('sounds', payload);
  config.save(function (err) {
    if (err) {
      res.send(500);
    }
  });
  res.send();
});

router.post('/upload', function (req, res, next) {
  var form = new multiparty.Form(),
    batch = new Batch();

  batch.push(function (cb) {
    form.on('field', function (name, value) {
      if (name === 'flowFilename') {
        cb(null, value);
      }
    });
  });

  batch.push(function (cb) {
    form.on('file', function (name, file) {
      cb(null, file.path);
    });
  });

  batch.end(function (err, results) {
    var streamFile = './uploads/' + results[0];
    fs.createReadStream(results[1])
      .pipe(fs.createWriteStream(streamFile, {
        flags: 'a'
      }));
  });

  form.parse(req);
  res.send();
});

module.exports = router;<commit_msg>Piping successful on file upload<commit_after>var fs = require('fs');
var Batch = require('batch');
var express = require('express');
var router = express.Router();
var config = require('./../lib/config');
var utils = require('./../lib/utils');
var multiparty = require('multiparty');

/* GET sounds configuration */
router.get('/', function (req, res) {
  res.json(config.get('sounds'));
});

/* Save configuration. */
router.put('/', function (req, res) {
  var payload = req.body;
  config.merge('sounds', payload);
  config.save(function (err) {
    if (err) {
      res.send(500);
    }
  });
  res.send();
});

router.post('/upload', function (req, res, next) {
  var form = new multiparty.Form(),
    batch = new Batch();

  batch.push(function (cb) {
    form.on('field', function (name, value) {
      if (name === 'flowFilename') {
        cb(null, value);
      }
    });
  });

  batch.push(function (cb) {
    form.on('file', function (name, file) {
      cb(null, file.path);
    });
  });

  batch.end(function (err, results) {
    var file = './uploads/' + results[0];
    fs.createReadStream(results[1])
      .pipe(fs.createWriteStream(file, {
        flags: 'a'
      }));

    res.send();
  });

  form.parse(req);
});

module.exports = router;
{'fraction_non_alphanumeric': 0.20613690007867821, 'fraction_numerical': 0.003933910306845004, 'mean_word_length': 3.0753205128205128, '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': '6153131', 'n_tokens_mistral': 854, 'n_tokens_neox': 837, 'n_words': 190}