<commit_before>(function () {
  "use strict";

  var connect = require('connect')
    , pathname = process.cwd()
    , fs = require('fs')
    , path = require('path')
    , app
    , version = JSON.parse(fs.readFileSync(path.join(__dirname, '/../package.json'), 'utf8')).version
    ;

  app = connect()
    .use(connect.static(pathname))
    .use(connect.directory(pathname))
    .use('/version', function (req, res, next) {
      res.end(version);
    })
    ;

  module.exports = app;
  module.exports.path = pathname;
}());
<commit_msg>Now handles POSTing files (but not to directories)<commit_after>/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
  "use strict";

  // TODO receive files
  var connect = require('connect')
    , pathname = process.cwd()
    , util = require('util')
    , fs = require('fs')
    , url = require('url')
    , path = require('path')
    , app
    , version = JSON.parse(fs.readFileSync(path.join(__dirname, '/../package.json'), 'utf8')).version
    ;

  app = connect()
    .use(connect.static(pathname))
    .use(connect.directory(pathname))
    .use(function (req, res, next) {
        var filename = url.parse(req.url).pathname.replace(/.*\//, '')
          , ws
          , err
          ;

        filename = filename || 'served-stream.bin';

        if (!/^POST$/i.exec(req.method)) {
          next();
        }

        util.print('Receiving ' + filename + ' ');

        try {
          // forgive me, for I have sinned
          fs.statSync(filename);
        } catch(e) {
          err = e;
        }

        if (!err) {
          console.log('hmm... that file exists, cancelling');
          res.end();
          return;
        }

        ws = fs.createWriteStream(filename);
        ws.on('error', function (err) {
          console.log('Had some problem... cancelling');
          console.error(err.message);
          res.end(err.message, 500);
        });
        req.on('data', function (chunk) {
          ws.write(chunk);
          util.print('.');
        });
        req.on('end', function () {
          ws.end();
          res.end();
          util.print(' done!');
          console.log();
        });
      })
    .use('/version', function (req, res, next) {
        res.end(version);
      })
    ;

  module.exports = app;
  module.exports.path = pathname;
}());

{'fraction_non_alphanumeric': 0.1740571902196436, 'fraction_numerical': 0.0024865312888520514, 'mean_word_length': 2.036477987421384, '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': '3892258', 'n_tokens_mistral': 778, 'n_tokens_neox': 751, 'n_words': 147}