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

Commit e6fa97a

Browse files
committed
refactor: use unixfs exporter with CID instances
Allows MFS to use the unixfs exporter that exports CIDs without API changes. refs ipfs-inactive/interface-js-ipfs-core#394 Depends on: * [ ] ipfs-inactive/js-ipfs-unixfs-exporter#19 License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent b47c0b0 commit e6fa97a

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"interface-datastore": "~0.6.0",
5959
"ipfs-multipart": "~0.1.0",
6060
"ipfs-unixfs": "~0.1.16",
61-
"ipfs-unixfs-exporter": "~0.35.5",
61+
"ipfs-unixfs-exporter": "github:ipfs/js-ipfs-unixfs-exporter#refactor/export-cid-instances",
6262
"ipfs-unixfs-importer": "~0.38.0",
6363
"ipld-dag-pb": "~0.15.2",
6464
"is-pull-stream": "~0.0.0",

src/core/ls-pull-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = (context) => {
103103
}
104104

105105
loadNode(context, {
106-
cid: file.hash
106+
cid: file.cid
107107
}, (err, result) => {
108108
if (err) {
109109
return cb(err)
@@ -114,7 +114,7 @@ module.exports = (context) => {
114114
cb(null, {
115115
name: file.name,
116116
type: FILE_TYPES[meta.type],
117-
hash: formatCid(file.hash, options.cidBase),
117+
hash: formatCid(file.cid, options.cidBase),
118118
size: meta.fileSize() || 0
119119
})
120120
})

src/core/mkdir.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const pull = require('pull-stream/pull')
88
const filter = require('pull-stream/throughs/filter')
99
const map = require('pull-stream/throughs/map')
1010
const collect = require('pull-stream/sinks/collect')
11-
const CID = require('cids')
1211
const {
1312
createNode,
1413
toMfsPath,
@@ -88,7 +87,7 @@ module.exports = (context) => {
8887
exported = currentPath
8988

9089
return {
91-
cid: new CID(node.hash),
90+
cid: node.cid,
9291
name: node.name
9392
}
9493
}),

src/core/stat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const pull = require('pull-stream/pull')
1111
const collect = require('pull-stream/sinks/collect')
1212
const asyncMap = require('pull-stream/throughs/async-map')
1313
const exporter = require('ipfs-unixfs-exporter')
14-
const CID = require('cids')
1514
const log = require('debug')('ipfs:mfs:stat')
1615

1716
const defaultOptions = {
@@ -43,7 +42,7 @@ module.exports = (context) => {
4342
asyncMap((file, cb) => {
4443
if (options.hash) {
4544
return cb(null, {
46-
hash: formatCid(new CID(file.hash), options.cidBase)
45+
hash: formatCid(file.cid, options.cidBase)
4746
})
4847
}
4948

@@ -54,7 +53,7 @@ module.exports = (context) => {
5453
}
5554

5655
loadNode(context, {
57-
cid: file.hash
56+
cid: file.cid
5857
}, (err, result) => {
5958
if (err) {
6059
return cb(err)

src/core/utils/to-trail.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const filter = require('pull-stream/throughs/filter')
77
const map = require('pull-stream/throughs/map')
88
const collect = require('pull-stream/sinks/collect')
99
const log = require('debug')('ipfs:mfs:utils:to-trail')
10-
const CID = require('cids')
1110

1211
const toTrail = (context, path, options, callback) => {
1312
const toExport = toPathComponents(path)
@@ -57,7 +56,7 @@ const toTrail = (context, path, options, callback) => {
5756

5857
return {
5958
name,
60-
cid: new CID(node.hash),
59+
cid: node.cid,
6160
size: node.size,
6261
type: node.type
6362
}

0 commit comments

Comments
 (0)