<commit_before>var assert = require('assert');
var fs = require('fs');
var path = require('path');
var medea = require('../');
var DataBuffer = require('../data_buffer');

var directory = __dirname + '/tmp/medea_test';
var db;

describe('Medea', function() {
  before(function(done) {
    require('rimraf')(directory, function () {
      db = medea({ maxFileSize: 1024*1024 });
      db.open(directory, function(err) {
        done();
      });
    })
  });

  it('has a max file size', function() {
    var db = medea();
    assert(db.maxFileSize > 0);
  });

  describe('initialize', function () {
    it('can be created as a factory', function () {
      assert(medea() instanceof medea);
    });

    it('successfully created as a Class', function () {
      assert((new medea()) instanceof medea);
    })
  });

  describe('#put', function() {
    it('successfully stores a String value', function(done) {
      db.put('hello', 'world', function(err) {
        assert(!err);
        done();
      });
    });

    it('successfully stores a Buffer value', function (done) {
      db.put('foo', new Buffer('bar'), function(err) {
        assert(!err);
        done();
      });
    });
  });

  describe('#get', function() {
    it('successfully retrieves a value', function(done) {
      db.put('hello', 'world', function(err) {
        db.get('hello', function(err, val) {
          assert.equal(val.toString(), 'world');
          done();
        });
      });
    });

    it('successfully retrieves a UTF-8 value', function(done) {
      db.put('hello', '\u2661', function(err) {
        db.get('hello', function(err, val) {
          assert.equal(val.toString(), '\u2661');
          done();
        });
      });
    });

    it('successfully retrieves a value', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('foo', function(err, val) {
          assert.equal(val.toString(), 'bar');
          done();
        });
      });
    });
    it('unsuccessfully retrieves a value', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('bar', function(err, val) {
          assert(!err);
          assert(!val);
          done();
        });
      });
    });
    it('unsuccessfully retrieves a value reserved key name', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('constructor', function(err, val) {
          assert(!err);
          assert(!val);
          done();
        });
      });
    });
    it('successfully recovers from zero-length entries', function(done) {
      var db;
      var directory = __dirname + '/tmp/medea_test2';
      require('rimraf')(directory, function () {
        db = medea({ maxFileSize: 1024*1024 });
        db.open(directory, function(err) {
          db.put('foo', new Buffer('bar'), function(err) {
            assert(!err);

            db.close(function(err) {
              assert(!err);

              fs.unlinkSync(path.join(directory, '1.medea.hint'));
              var contents = fs.readFileSync(path.join(directory, '1.medea.data'));

              var empty = new Buffer(18);
              empty.fill(0)

              var buf = Buffer.concat([empty, contents]);

              var fd = fs.openSync(path.join(directory, '1.medea.data'), 'w+');
              fs.write(fd, buf, 0, buf.length, function(err) {
                fs.closeSync(fd);

                db.open(directory, function(err) {
                  assert(!err);

                  db.get('foo', function(err, val) {
                    assert(!err);

                    assert.equal(val.toString(), 'bar');

                    done();
                  });
                });
              });
            });
          });
        });
      })
    });
  });
<commit_msg>Fixing 0.10 support.<commit_after>var assert = require('assert');
var fs = require('fs');
var path = require('path');
var medea = require('../');
var DataBuffer = require('../data_buffer');

var directory = __dirname + '/tmp/medea_test';
var db;

describe('Medea', function() {
  before(function(done) {
    require('rimraf')(directory, function () {
      db = medea({ maxFileSize: 1024*1024 });
      db.open(directory, function(err) {
        done();
      });
    })
  });

  it('has a max file size', function() {
    var db = medea();
    assert(db.maxFileSize > 0);
  });

  describe('initialize', function () {
    it('can be created as a factory', function () {
      assert(medea() instanceof medea);
    });

    it('successfully created as a Class', function () {
      assert((new medea()) instanceof medea);
    })
  });

  describe('#put', function() {
    it('successfully stores a String value', function(done) {
      db.put('hello', 'world', function(err) {
        assert(!err);
        done();
      });
    });

    it('successfully stores a Buffer value', function (done) {
      db.put('foo', new Buffer('bar'), function(err) {
        assert(!err);
        done();
      });
    });
  });

  describe('#get', function() {
    it('successfully retrieves a value', function(done) {
      db.put('hello', 'world', function(err) {
        db.get('hello', function(err, val) {
          assert.equal(val.toString(), 'world');
          done();
        });
      });
    });

    it('successfully retrieves a UTF-8 value', function(done) {
      db.put('hello', '\u2661', function(err) {
        db.get('hello', function(err, val) {
          assert.equal(val.toString(), '\u2661');
          done();
        });
      });
    });

    it('successfully retrieves a value', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('foo', function(err, val) {
          assert.equal(val.toString(), 'bar');
          done();
        });
      });
    });
    it('unsuccessfully retrieves a value', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('bar', function(err, val) {
          assert(!err);
          assert(!val);
          done();
        });
      });
    });
    it('unsuccessfully retrieves a value reserved key name', function(done) {
      db.put('foo', new Buffer('bar'), function(err) {
        db.get('constructor', function(err, val) {
          assert(!err);
          assert(!val);
          done();
        });
      });
    });
    it('successfully recovers from zero-length entries', function(done) {
      var db;
      var directory = __dirname + '/tmp/medea_test2';
      require('rimraf')(directory, function () {
        db = medea({ maxFileSize: 1024*1024 });
        db.open(directory, function(err) {
          db.put('foo', new Buffer('bar'), function(err) {
            assert(!err);

            db.close(function(err) {
              assert(!err);

              fs.unlinkSync(path.join(directory, '1.medea.hint'));
              var contents = fs.readFileSync(path.join(directory, '1.medea.data'));

              var empty = new Buffer(18);
              empty.fill(0)

              var buf = Buffer.concat([empty, contents]);

              var fd = fs.openSync(path.join(directory, '1.medea.data'), 'w+');
              fs.write(fd, buf, 0, buf.length, 0, function(err) {
                fs.closeSync(fd);

                db.open(directory, function(err) {
                  assert(!err);

                  db.get('foo', function(err, val) {
                    assert(!err);

                    assert.equal(val.toString(), 'bar');

                    done();
                  });
                });
              });
            });
          });
        });
      })
    });
  });

{'fraction_non_alphanumeric': 0.1796116504854369, 'fraction_numerical': 0.009446339543426921, 'mean_word_length': 1.9941084053417124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7347681', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2195, 'n_words': 471}