<commit_before>var Busboy = require('busboy'),
  debug = require('debug')('share'),
  fs = require('fs'),
  path = require('path'),
  Q = require('q'),
  rimraf = require('rimraf'),
  sanitize = require('sanitize-filename');

function Upload(name, file, config, random) {
  if (!(this instanceof Upload)) {
    return new Upload(name, file, config, random);
  }

  this.name = sanitize(name).replace(/ /g, "_");
  this.file = file;
  this.config = config;
  this.random = random;
  this.writeStream = null;
  this.aborted = false;
}

Upload.prototype.start = function() {
  var self = this;
  console.log(this);

  return self.pipeToTmpFile()
    .then(function() {
      return self.moveToUploadDir();
    });
}

Upload.prototype.pipeToTmpFile = function() {
  var self = this,
    deferred = Q.defer(),
    tmpFile = path.join(self.config.tmpDir, self.random);

  self.writeStream = fs.createWriteStream(tmpFile);

  function onError(err) {
    self.file.unpipe();
    self.writeStream.destroy();
    deferred.reject(err);
  }

  function onFinish() {
    self.writeStream.on('close', onClose);
  }

  function onClose() {
    deferred.resolve();
  }
<commit_msg>remove debug info<commit_after>var Busboy = require('busboy'),
  debug = require('debug')('share'),
  fs = require('fs'),
  path = require('path'),
  Q = require('q'),
  rimraf = require('rimraf'),
  sanitize = require('sanitize-filename');

function Upload(name, file, config, random) {
  if (!(this instanceof Upload)) {
    return new Upload(name, file, config, random);
  }

  this.name = sanitize(name).replace(/ /g, "_");
  this.file = file;
  this.config = config;
  this.random = random;
  this.writeStream = null;
  this.aborted = false;
}

Upload.prototype.start = function() {
  var self = this;

  return self.pipeToTmpFile()
    .then(function() {
      return self.moveToUploadDir();
    });
}

Upload.prototype.pipeToTmpFile = function() {
  var self = this,
    deferred = Q.defer(),
    tmpFile = path.join(self.config.tmpDir, self.random);

  self.writeStream = fs.createWriteStream(tmpFile);

  function onError(err) {
    self.file.unpipe();
    self.writeStream.destroy();
    deferred.reject(err);
  }

  function onFinish() {
    self.writeStream.on('close', onClose);
  }

  function onClose() {
    deferred.resolve();
  }

{'fraction_non_alphanumeric': 0.16428880242109814, 'fraction_numerical': 0.0, 'mean_word_length': 3.600397614314115, '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': '6148204', 'n_tokens_mistral': 783, 'n_tokens_neox': 772, 'n_words': 157}