<commit_before>var EventEmitter = require('events').EventEmitter

var sublevel = module.exports = function (nut, prefix, createStream) {
  var emitter = new EventEmitter()
  emitter.sublevels = {}
  prefix = prefix || []
  createStream = createStream || function (e) { return e }
  emitter.put = function (key, value, opts, cb) {
    if('function' === typeof opts) cb = opts, opts = {}

    nut.apply([{
      key: key, value: value,
      prefix: prefix.slice(), type: 'put'
    }], opts, function (err) {
      if(err) return cb(err)
      emitter.emit('put', key, value); cb(null)
    })
  }

  emitter.prefix = function () {
    return prefix.slice()
  }

  emitter.del = function (key, opts, cb) {
    if('function' === typeof opts) cb = opts, opts = {}

    nut.apply([{
      key: key,
      prefix: prefix.slice(), type: 'del'
    }], opts, function (err) {
      if(err) return cb(err)
      emitter.emit('del', key); cb(null)
    })
  }

  emitter.batch = function (ops, opts, cb) {
    if('function' === typeof opts)
      cb = opts, opts = {}
    ops = ops.map(function (op) {
      return {
        key:           op.key,
        value:         op.value,
        prefix:        op.prefix || prefix,
        keyEncoding:   op.keyEncoding,    // *
        valueEncoding: op.valueEncoding,  // * (TODO: encodings on sublevel)
      }
    })
    nut.apply(ops, opts, function (err) {
      if(err) return cb(err)
      emitter.emit('batch', ops); cb(null)
    })
  }

  emitter.get = function (key, opts, cb) {
    if('function' === typeof opts) 
      cb = opts, opts = {}
    nut.get(key, prefix, opts, cb)
  }

  emitter.sublevel = function (name) {
    return emitter.sublevels[name] =
      emitter.sublevels[name] || sublevel(nut, prefix.concat(name), createStream)
  }

  emitter.pre = function (key, hook) {
    if('function' === typeof key) return nut.pre([prefix], key)
    if('string'   === typeof key) return nut.pre([prefix, key], hook)
    //TODO: {lt, lte, gt, gte}
    throw new Error('not implemented')
  }

  emitter.post = function (key, hook) {
    if('function' === typeof key) return nut.post([prefix], key)
    if('string'   === typeof key) return nut.post([prefix, key], hook)

    //TODO: handle ranges, needed for level-live-stream, etc.
    throw new Error('not implemented')
  }

  emitter.createReadStream = function (opts) {
    opts = opts || {}
    opts.prefix = prefix
    var stream
    var it = nut.iterator(opts, function (err, it) {
      stream.setIterator(it)
    })
    stream = createStream(opts, nut.createDecoder(opts))
    if(it) stream.setIterator(it)
    return stream
  }

  return emitter
}
<commit_msg>handle if there is no callback<commit_after>var EventEmitter = require('events').EventEmitter

var sublevel = module.exports = function (nut, prefix, createStream) {
  var emitter = new EventEmitter()
  emitter.sublevels = {}
  prefix = prefix || []
  function errback (err) { if (err) emitter.emit('error', error)}
  createStream = createStream || function (e) { return e }
  emitter.put = function (key, value, opts, cb) {
    if('function' === typeof opts) cb = opts, opts = {}
    if(!cb) cb = errback

    nut.apply([{
      key: key, value: value,
      prefix: prefix.slice(), type: 'put'
    }], opts || {}, function (err) {
      if(err) return cb(err)
      emitter.emit('put', key, value); cb(null)
    })
  }

  emitter.prefix = function () {
    return prefix.slice()
  }

  emitter.del = function (key, opts, cb) {
    if('function' === typeof opts) cb = opts, opts = {}
    if(!cb) cb = errback

    nut.apply([{
      key: key,
      prefix: prefix.slice(), type: 'del'
    }], opts, function (err) {
      if(err) return cb(err)
      emitter.emit('del', key); cb(null)
    })
  }

  emitter.batch = function (ops, opts, cb) {
    if('function' === typeof opts)
      cb = opts, opts = {}
    if(!cb) cb = errback

    ops = ops.map(function (op) {
      return {
        key:           op.key,
        value:         op.value,
        prefix:        op.prefix || prefix,
        keyEncoding:   op.keyEncoding,    // *
        valueEncoding: op.valueEncoding,  // * (TODO: encodings on sublevel)
      }
    })
    nut.apply(ops, opts, function (err) {
      if(err) return cb(err)
      emitter.emit('batch', ops); cb(null)
    })
  }

  emitter.get = function (key, opts, cb) {
    if('function' === typeof opts) 
      cb = opts, opts = {}
    nut.get(key, prefix, opts, cb)
  }

  emitter.sublevel = function (name) {
    return emitter.sublevels[name] =
      emitter.sublevels[name] || sublevel(nut, prefix.concat(name), createStream)
  }

  emitter.pre = function (key, hook) {
    if('function' === typeof key) return nut.pre([prefix], key)
    if('string'   === typeof key) return nut.pre([prefix, key], hook)
    throw new Error('not implemented')
  }

  emitter.post = function (key, hook) {
    if('function' === typeof key) return nut.post([prefix], key)
    if('string'   === typeof key) return nut.post([prefix, key], hook)

    //TODO: handle ranges, needed for level-live-stream, etc.
    throw new Error('not implemented')
  }

  emitter.createReadStream = function (opts) {
    opts = opts || {}
    opts.prefix = prefix
    var stream
    var it = nut.iterator(opts, function (err, it) {
      stream.setIterator(it)
    })

    stream = createStream(opts, nut.createDecoder(opts))
    if(it) stream.setIterator(it)

    return stream
  }

  return emitter
}

{'fraction_non_alphanumeric': 0.15689149560117302, 'fraction_numerical': 0.0, 'mean_word_length': 2.6355762824783477, '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': '2414616', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1743, 'n_words': 472}