<commit_before>'use strict';

var inherits = require('util').inherits;
var Transform = require('stream').Transform;
var PluginError = require('gulp-util').PluginError;



function gulpTransform(transformFn, options) {
  if (isNone(transformFn)) {
    throwPluginError('transformFn must be defined');
  } else if (typeof transformFn !== 'function') {
    throwPluginError('transformFn must be a function');
  } else if (!isNone(options) && !/^(function|object)$/.test(typeof options)) {
    throwPluginError('options must be an object if defined');
  } else {
    return new GulpTransformStream(transformFn, options);
  }
}



function GulpTransformStream(transformFn, options) {
  Transform.call(this, {objectMode: true});
  this.transformFn = transformFn;
  this.options = options || {};
}

inherits(GulpTransformStream, Transform);

GulpTransformStream.prototype._transform = function(file, encoding, next) {
  if (file.isBuffer()) {
    file.contents = transformContents(this.transformFn, file.contents, file, this.options);
  }

  if (file.isStream()) {
    file.contents = file.contents.pipe(new FileStream(this.transformFn, file, this.options));
  }

  next(null, file);
};



function FileStream(transformFn, file, options) {
  Transform.call(this);
  this.transformFn = transformFn;
  this.file = file;
  this.options = options;
  this.data = [];
}

inherits(FileStream, Transform);

FileStream.prototype._transform = function(chunk, encoding, next) {
  this.data.push(chunk);
  next();
};

FileStream.prototype._flush = function(done) {
  var contents = Buffer.concat(this.data);
  this.push(transformContents(this.transformFn, contents, this.file, this.options));
  done();
};



function transformContents(transformFn, contents, file, options) {
  contents = options.encoding ? contents.toString(options.encoding) : contents;
  contents = transformFn.call(options.thisArg, contents, file);
<commit_msg>Fix style<commit_after>'use strict';

var inherits = require('util').inherits;
var Transform = require('stream').Transform;
var PluginError = require('gulp-util').PluginError;



function gulpTransform(transformFn, options) {
  if (isNone(transformFn)) {
    throwPluginError('transformFn must be defined');
  } else if (typeof transformFn !== 'function') {
    throwPluginError('transformFn must be a function');
  } else if (!isNone(options) && !/^(function|object)$/.test(typeof options)) {
    throwPluginError('options must be an object if defined');
  } else {
    return new GulpTransformStream(transformFn, options);
  }
}



function GulpTransformStream(transformFn, options) {
  Transform.call(this, {objectMode: true});
  this.transformFn = transformFn;
  this.options = options || {};
}

inherits(GulpTransformStream, Transform);

GulpTransformStream.prototype._transform = function(file, encoding, next) {
  if (file.isBuffer()) {
    file.contents = transformContents(
      this.transformFn, file.contents, file, this.options);
  }

  if (file.isStream()) {
    file.contents = file.contents.pipe(
      new FileStream(this.transformFn, file, this.options));
  }

  next(null, file);
};



function FileStream(transformFn, file, options) {
  Transform.call(this);
  this.transformFn = transformFn;
  this.file = file;
  this.options = options;
  this.data = [];
}

inherits(FileStream, Transform);

FileStream.prototype._transform = function(chunk, encoding, next) {
  this.data.push(chunk);
  next();
};

FileStream.prototype._flush = function(done) {
  var contents = Buffer.concat(this.data);
  this.push(transformContents(
    this.transformFn, contents, this.file, this.options));
  done();
};



function transformContents(transformFn, contents, file, options) {
  contents = options.encoding ? contents.toString(options.encoding) : contents;
  contents = transformFn.call(options.thisArg, contents, file);

{'fraction_non_alphanumeric': 0.13850559750065086, 'fraction_numerical': 0.0, 'mean_word_length': 4.993759750390016, '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': '7668223', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1119, 'n_words': 248}