Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #4

Merged
merged 2 commits into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions lib/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@ var memoized_lookup
function _lookup (ipfs, hash, lookfor, cb) {
ipfs.object.get(hash, function (err, res) {
if (err) {
cb(err, null)
} else {
return cb(err, null)
}

try {
var obj = JSON.parse(res.Data)
} catch (err) {
return cb(err, null)
}

var child = 0
if (obj.type === 'Node') {
while (obj.mins[child] &&
obj.mins[child] <= lookfor) {
child++
}
return memoized_lookup(ipfs, res.Links[child - 1].Hash, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] &&
obj.data[child].min <= lookfor) {
child++
}

var child = 0
if (obj.type === 'Node') {
while (obj.mins[child] &&
obj.mins[child] <= lookfor) {
child++
}
return memoized_lookup(ipfs, res.Links[child - 1].Hash, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] &&
obj.data[child].min <= lookfor) {
child++
}

if (obj.data[child - 1].data) {
cb(null, formatData(obj.data[child - 1].data))
} else {
cb('Unmapped range', null)
}
if (obj.data[child - 1].data) {
cb(null, formatData(obj.data[child - 1].data))
} else {
cb('Unmapped range', null)
}
}
})
Expand Down
7 changes: 5 additions & 2 deletions lib/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ module.exports = function lookupPretty (ipfs, multiaddrs, cb) {
if (multiaddrs.length === 0) return cb(null, null)
if (typeof multiaddrs === 'string') multiaddrs = [multiaddrs]

var address = multiaddrs[0].split('/')[2]
if (isLocal(address)) return lookupPretty(ipfs, multiaddrs.slice(1), cb)
var current = multiaddrs[0].split('/')
var address = current[2]

// No ip6 support at the moment
if (isLocal(address) || current[1] === 'ip6') return lookupPretty(ipfs, multiaddrs.slice(1), cb)

lookup(ipfs, address, function (err, res) {
if (err) return cb(err)
Expand Down