Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit c060b53

Browse files
committed
exporter: more elegant type checking
1 parent b446b0d commit c060b53

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed
File renamed without changes.

src/exporter/resolve.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const resolvers = {
77
directory: require('./dir-flat'),
88
'hamt-sharded-directory': require('./dir-hamt-sharded'),
99
file: require('./file'),
10-
unknown: require('./unknown')
10+
object: require('./object')
1111
}
1212

1313
module.exports = Object.assign({
@@ -16,12 +16,7 @@ module.exports = Object.assign({
1616
}, resolvers)
1717

1818
function resolve (node, hash, pathRest, ipldResolver, parentNode) {
19-
let type
20-
try {
21-
type = typeOf(node)
22-
} catch (err) {
23-
type = 'unknown'
24-
}
19+
const type = typeOf(node)
2520
const resolver = resolvers[type]
2621
if (!resolver) {
2722
return pull.error(new Error('Unkown node type ' + type))
@@ -30,6 +25,9 @@ function resolve (node, hash, pathRest, ipldResolver, parentNode) {
3025
}
3126

3227
function typeOf (node) {
33-
const data = UnixFS.unmarshal(node.data)
34-
return data.type
28+
if (Buffer.isBuffer(node.data)) {
29+
return UnixFS.unmarshal(node.data).type
30+
} else {
31+
return 'object'
32+
}
3533
}

0 commit comments

Comments
 (0)