Skip to content

Instantly share code, notes, and snippets.

@Juul
Last active July 2, 2019 21:48
Show Gist options
  • Save Juul/0ec617abba0c0822a6c0973fad50f9a9 to your computer and use it in GitHub Desktop.
Save Juul/0ec617abba0c0822a6c0973fad50f9a9 to your computer and use it in GitHub Desktop.
Simple tool to dump the contents of leveldb databases
#!/usr/bin/env node
var fs = require('fs');
try {
var level = require('level');
} catch(e) {
console.error("You must have the node module `level` installed.");
console.error("To install run: `npm install level`");
process.exit(1);
}
if(process.argv.length !== 3) {
console.error("Usage: leveldump <path_to_db>");
process.exit(1)
}
var dbPath = process.argv[2];
try {
var stats = fs.statSync(dbPath);
} catch(e) {
console.error("No such leveldb database");
process.exit(1)
}
if(!stats.isDirectory()) {
console.error("No such leveldb database");
process.exit(1)
}
try {
var db = level(dbPath, {valueEncoding: 'json'});
} catch(e) {
console.error("Could not open leveldb database");
process.exit(1)
}
s = db.createReadStream();
s.on('data', function(data) {
console.log(data.key, data.value);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment