Skip to content

Instantly share code, notes, and snippets.

@braydonf
Last active September 28, 2016 16:41
Show Gist options
  • Save braydonf/9cad7ff7d53311fe5aeb62a4c9e455d3 to your computer and use it in GitHub Desktop.
Save braydonf/9cad7ff7d53311fe5aeb62a4c9e455d3 to your computer and use it in GitHub Desktop.
lmdb-test.js
describe('Cursors (utf16 string key and binary value)', function() {
this.timeout(10000);
var env;
var dbi;
var total = 10;
before(function() {
env = new lmdb.Env();
env.open({
path: testDirPath,
maxDbs: maxDbs,
mapSize: 16 * 1024 * 1024 * 1024
});
dbi = env.openDbi({
name: 'utf16skey',
create: true
});
var txn = env.beginTxn();
var c = 0;
while(c < total) {
var buffer = new Buffer(new Array(8));
buffer.writeDoubleBE(c);
txn.putBinary(dbi, c.toString() + '-key', buffer);
c++;
}
txn.commit();
});
after(function() {
dbi.close();
env.close();
});
it('will retrieve utf16 string keys as buffer', function() {
var txn = env.beginTxn();
var cursor = new lmdb.Cursor(txn, dbi);
cursor.goToLast();
cursor.getCurrentBinary(function(key, value) {
key.toString('ucs2').replace('\u0000', '').should.equal('9-key');
should.exist(value);
});
txn.abort();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment