Created
April 10, 2018 22:16
-
-
Save mafintosh/08c29ff876f0444b7270cf8335cbf650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iterate (db, onnode, done) { | |
visit(db, [], onnode, cb) | |
} | |
function visit (db, path, onnode, cb) { | |
var val = 0 | |
loop(null) | |
function loop (err) { | |
if (err) return cb(err) | |
if (val > 4) return cb(null) | |
var next = path.concat(val++) | |
db.get('', {path: next, prefix: true}, function (err, nodes) { | |
if (err) return cb(err) | |
for (var i = 0; i < nodes.length; i++) { | |
var node = nodes[i] | |
if (node.path.join('') === next.join('')) onnode(node) | |
} | |
if (!nodes.length) return loop(null) | |
visit(db, next, onnode, loop) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment