<commit_before>var util = require('util');
var binding = require('./incremental');
var algorithms = {};

exports.getHashes = function() {
  return Object.keys(binding)
        .filter(function(name) {
          return 'function' === typeof binding[name];
        })
        .map(function(name) { return name.toLowerCase(); });
};

Object.keys(binding).forEach(function(name) {
  if (binding.hasOwnProperty(name) && 'function' === typeof binding[name]) {
    algorithms[name.toLowerCase()] = binding[name];
  }
});

algorithms['murmurhash3a'] = algorithms['murmurhash32'] = algorithms['murmurhash32x86'] = algorithms['murmurhash']

/* from nodejs lib/crypto.js */

var LazyTransform = require('./lazy_transform');

/**
 * Creates and returns a MurmurHash object that can be used to generate murmurhash digests.
 * 
 * Except murmur's `seed` option, the rest of the options are passed to
 * stream.Transform constructor.
 *
 * @param {string|MurmurHash} algorithm|hasher - one of available algorithms
 *                            or a murmur hasher instance
 * @param {number|object} seed|options - hasher options
 **/
exports.createHash = exports.MurmurHash = MurmurHash;
function MurmurHash(algorithm, options) {
  var seed;

  if (!(this instanceof MurmurHash))
    return new MurmurHash(algorithm, options);

  if ('number' === typeof options)
    seed = options, options = undefined;
  else if (options)
    seed = options.seed;

  if (algorithm instanceof MurmurHash) {
    this._handle = new algorithm._handle.constructor(algorithm._handle);
  } else if (algorithm) {
    var Handle = algorithms[algorithm.toLowerCase()];
    if (Handle) {
      this._handle = new Handle(seed);
    } else {
      throw new Error("Algorithm not supported");
    }
  } else {
    throw new TypeError("Must give algorithm string or MurmurHash instance");
  }

  LazyTransform.call(this, options);
}

util.inherits(MurmurHash, LazyTransform);

MurmurHash.prototype._transform = function(chunk, encoding, callback) {
  this._handle.update(chunk, encoding);
  callback();
};

MurmurHash.prototype._flush = function(callback) {
  this.push(this._handle.digest());
  callback();
};

MurmurHash.prototype.update = function(data, encoding) {
  this._handle.update(data, encoding);
  return this;
};

MurmurHash.prototype.digest = function(outputEncoding) {
  return this._handle.digest(outputEncoding);
};

MurmurHash.prototype.serialize = function(type, offset) {
  return this._handle.serialize(type, offset);
};

MurmurHash.prototype.copy = function(target) {
  this._handle.copy(target && target._handle);
  return target;
};

MurmurHash.prototype.toJSON = function() {
  var handle = this._handle;
  return {
    type: handle.constructor.name,
    state: handle.toJSON()
  };
};

Object.defineProperty(MurmurHash.prototype, 'total', {
  get: function() {
    return this._handle.total;
  },
  enumerable: true,
  configurable: true
});

Object.defineProperty(MurmurHash.prototype, 'SERIAL_BYTE_LENGTH', {
  get: function() {
    Object.defineProperty(this, 'SERIAL_BYTE_LENGTH', {
      enumerable: true,
      writable: true,
      configurable: true,
      value: this._handle.SERIAL_BYTE_LENGTH
    });
    return this.SERIAL_BYTE_LENGTH;
  },
  enumerable: true,
  configurable: true,
});
<commit_msg>stream: allow second argument to be serialized string<commit_after>var util = require('util');
var binding = require('./incremental');
var algorithms = {};

exports.getHashes = function() {
  return Object.keys(binding)
        .filter(function(name) {
          return 'function' === typeof binding[name];
        })
        .map(function(name) { return name.toLowerCase(); });
};

Object.keys(binding).forEach(function(name) {
  if (binding.hasOwnProperty(name) && 'function' === typeof binding[name]) {
    algorithms[name.toLowerCase()] = binding[name];
  }
});

algorithms['murmurhash3a'] = algorithms['murmurhash32'] = algorithms['murmurhash32x86'] = algorithms['murmurhash']

/* from nodejs lib/crypto.js */

var LazyTransform = require('./lazy_transform');

/**
 * Creates and returns a MurmurHash object that can be used to generate murmurhash digests.
 * 
 * Except murmur's `seed` option, the rest of the options are passed to
 * stream.Transform constructor.
 *
 * @param {string|MurmurHash} algorithm|hasher - one of available algorithms
 *                            or a murmur hasher instance
 * @param {number|object} seed|options - hasher options
 **/
exports.createHash = exports.MurmurHash = MurmurHash;
function MurmurHash(algorithm, options) {
  var seed;

  if (!(this instanceof MurmurHash))
    return new MurmurHash(algorithm, options);

  if (options && 'object' === typeof options) {
    seed = options.seed;
  } else {
    seed = options, options = undefined;
  }

  if (algorithm instanceof MurmurHash) {
    this._handle = new algorithm._handle.constructor(algorithm._handle);
  } else if (algorithm) {
    var Handle = algorithms[algorithm.toLowerCase()];
    if (Handle) {
      this._handle = new Handle(seed);
    } else {
      throw new Error("Algorithm not supported");
    }
  } else {
    throw new TypeError("Must give algorithm string or MurmurHash instance");
  }

  LazyTransform.call(this, options);
}

util.inherits(MurmurHash, LazyTransform);

MurmurHash.prototype._transform = function(chunk, encoding, callback) {
  this._handle.update(chunk, encoding);
  callback();
};

MurmurHash.prototype._flush = function(callback) {
  this.push(this._handle.digest());
  callback();
};

MurmurHash.prototype.update = function(data, encoding) {
  this._handle.update(data, encoding);
  return this;
};

MurmurHash.prototype.digest = function(outputEncoding) {
  return this._handle.digest(outputEncoding);
};

MurmurHash.prototype.serialize = function(type, offset) {
  return this._handle.serialize(type, offset);
};

MurmurHash.prototype.copy = function(target) {
  this._handle.copy(target && target._handle);
  return target;
};

MurmurHash.prototype.toJSON = function() {
  var handle = this._handle;
  return {
    type: handle.constructor.name,
    state: handle.toJSON()
  };
};

Object.defineProperty(MurmurHash.prototype, 'total', {
  get: function() {
    return this._handle.total;
  },
  enumerable: true,
  configurable: true
});

Object.defineProperty(MurmurHash.prototype, 'SERIAL_BYTE_LENGTH', {
  get: function() {
    Object.defineProperty(this, 'SERIAL_BYTE_LENGTH', {
      enumerable: true,
      writable: true,
      configurable: true,
      value: this._handle.SERIAL_BYTE_LENGTH
    });
    return this.SERIAL_BYTE_LENGTH;
  },
  enumerable: true,
  configurable: true,
});

{'fraction_non_alphanumeric': 0.13288084464555053, 'fraction_numerical': 0.0021116138763197585, 'mean_word_length': 4.038753799392097, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2032009', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1961, 'n_words': 454}