<commit_before>var collect = require('collect-stream');
var inherits = require('inherits');
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN;
var prefix = require('./prefix.js');
var xtend = require('xtend');
var notFound = require('./not_found.js');

module.exports = Cow;
inherits(Cow, AbstractLevelDOWN);

function Cow (db, key) {
  if (!(this instanceof Cow)) return new Cow(db, key);
  this._db = db;
  this._key = key;
}

Cow.prototype._open = function (opts, cb) {
  var self = this;
  process.nextTick(function () { cb(null, self) });
};

Cow.prototype._prefix = function (pre, key) {
  return prefix(pre, this._key, key);
};

Cow.prototype._xget = function (pkey, key, opts, cb) {
  var self = this;
  self._db.get(prefix('d', pkey, key), opts, function (err, value) {
    if (err && notFound(err)) get()
    else if (err) cb(err)
    else cb(new Error('not found'), undefined, true)
  });
  function get () {
    self._db.get(prefix('n', pkey, key), opts, cb);
  }
};

Cow.prototype._get = function (key, opts, cb) {
  var self = this;
  self._xget(self._key, key, opts, onxget);
  
  function onxget (err, value, deleted) {
    if (deleted) cb(err)
    else if (err && notFound(err)) {
      checkp(self._key, cb)
    }
    else cb(err, value)
  }
  function checkp (pkey, cb) {
    self._getPrev(pkey, function (err, prev) {
      if (err) return cb(err)
      if (prev.length === 0) return cb(new Error('not found'))
      
      (function next () {
        if (prev.length === 0) {
          return cb(new Error('not found'));
        }
        var p = prev.shift();
        self._xget(p, key, opts, function (err, value, deleted) {
          if (deleted) return cb(err);
          else if (err && notFound(err)) {
            checkp(p, function (err, value) {
              if (err && notFound(err)) next()
              else cb(err, value)
            });
          }
        });
      })();
    });
  }
};
<commit_msg>basic example works<commit_after>var collect = require('collect-stream');
var inherits = require('inherits');
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN;
var prefix = require('./prefix.js');
var xtend = require('xtend');
var notFound = require('./not_found.js');

module.exports = Cow;
inherits(Cow, AbstractLevelDOWN);

function Cow (db, key) {
  if (!(this instanceof Cow)) return new Cow(db, key);
  this._db = db;
  this._key = key;
}

Cow.prototype._open = function (opts, cb) {
  var self = this;
  process.nextTick(function () { cb(null, self) });
};

Cow.prototype._prefix = function (pre, key) {
  return prefix(pre, this._key, key);
};

Cow.prototype._xget = function (pkey, key, opts, cb) {
  var self = this;
  self._db.get(prefix('d', pkey, key), opts, function (err, value) {
    if (err && notFound(err)) get()
    else if (err) cb(err)
    else cb(new Error('not found'), undefined, true)
  });
  function get () {
    self._db.get(prefix('n', pkey, key), opts, cb);
  }
};

Cow.prototype._get = function (key, opts, cb) {
  var self = this;
  self._xget(self._key, key, opts, onxget);
  
  function onxget (err, value, deleted) {
    if (deleted) cb(err)
    else if (err && notFound(err)) {
      checkp(self._key, cb)
    }
    else cb(err, value)
  }
  function checkp (pkey, cb) {
    self._getPrev(pkey, function (err, prev) {
      if (err) return cb(err);
      ;(function next () {
        if (prev.length === 0) {
          return cb(new Error('not found'));
        }
        var p = prev.shift();
        self._xget(p, key, opts, function (err, value, deleted) {
          if (deleted) return cb(err);
          else if (err && notFound(err)) {
            checkp(p, function (err, value) {
              if (err && notFound(err)) next()
              else cb(err, value)
            });
          }
          else cb(err, value)
        });
      })();
    });
  }
};

{'fraction_non_alphanumeric': 0.16864057672502575, 'fraction_numerical': 0.000772399588053553, 'mean_word_length': 2.721264367816092, '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': '6763603', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1311, 'n_words': 356}