<commit_before>var lexint = require('lexicographic-integer')
var collect = require('stream-collector')
var through = require('through2')
var from = require('from2')
var pump = require('pump')

var noop = function () {}

var Logs = function (db, opts) {
  if (!(this instanceof Logs)) return new Logs(db, opts)
  if (!opts) opts = {}

  this.db = db
  this.sep = opts.separator || opts.sep || '!'
  this.prefix = opts.prefix ? this.sep + opts.prefix + this.sep : ''
  this.valueEncoding = opts.valueEncoding
}

Logs.prototype.key = function (log, seq) {
  return this.prefix + log + this.sep + (seq === -1 ? '\xff' : lexint.pack(seq, 'hex'))
}

Logs.prototype.list = function (cb) {
  var self = this

  var prev = this.prefix
  var rs = from.obj(function (size, cb) {
    collect(self.db.createKeyStream({gt: prev, limit: 1}), function (err, keys) {
      if (err) return cb(err)
      if (!keys.length) return cb(null, null)
      var log = keys[0].slice(0, keys[0].lastIndexOf(self.sep))
      prev = self.key(log, -1)
      cb(null, log)
    })
  })

  return collect(rs, cb)
}
<commit_msg>fix list when using prefix<commit_after>var lexint = require('lexicographic-integer')
var collect = require('stream-collector')
var through = require('through2')
var from = require('from2')
var pump = require('pump')

var noop = function () {}

var Logs = function (db, opts) {
  if (!(this instanceof Logs)) return new Logs(db, opts)
  if (!opts) opts = {}

  this.db = db
  this.sep = opts.separator || opts.sep || '!'
  this.prefix = opts.prefix ? this.sep + opts.prefix + this.sep : ''
  this.valueEncoding = opts.valueEncoding
}

Logs.prototype.key = function (log, seq) {
  return this.prefix + log + this.sep + (seq === -1 ? '\xff' : lexint.pack(seq, 'hex'))
}

Logs.prototype.list = function (cb) {
  var self = this
  var prev = this.prefix
  var end = prev + '\xff'

  var rs = from.obj(function (size, cb) {
    collect(self.db.createKeyStream({gt: prev, lt: end, limit: 1}), function (err, keys) {
      if (err) return cb(err)

      if (!keys.length) return cb(null, null)
      var log = keys[0].slice(self.prefix.length, keys[0].lastIndexOf(self.sep))
      prev = self.key(log, -1)

      cb(null, log)
    })
  })

  return collect(rs, cb)
}

{'fraction_non_alphanumeric': 0.16822015090989792, 'fraction_numerical': 0.006657789613848202, 'mean_word_length': 3.368217054263566, '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': '2152890', 'n_tokens_mistral': 796, 'n_tokens_neox': 778, 'n_words': 212}