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

Commit 7335477

Browse files
committed
fix: use pipeline customisation instead of bloating importer
1 parent 8e5d241 commit 7335477

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"ipfs-multipart": "^0.3.0",
7474
"ipfs-unixfs": "^0.3.0",
7575
"ipfs-unixfs-exporter": "^0.40.0",
76-
"ipfs-unixfs-importer": "ipfs/js-ipfs-unixfs-importer#support-dagnodes-as-content",
76+
"ipfs-unixfs-importer": "ipfs/js-ipfs-unixfs-importer#expose-internals-for-customisation",
7777
"ipfs-utils": "^0.4.2",
7878
"ipld-dag-pb": "^0.18.0",
7979
"it-last": "^1.0.1",

src/core/chmod.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const exporter = require('ipfs-unixfs-exporter')
1818
const last = require('it-last')
1919
const cp = require('./cp')
2020
const rm = require('./rm')
21+
const persist = require('ipfs-unixfs-importer/src/utils/persist')
2122

2223
const defaultOptions = {
2324
flush: true,
@@ -191,7 +192,23 @@ module.exports = (context) => {
191192
}
192193
}
193194
},
194-
(source) => importer(source, context.ipld, options),
195+
(source) => importer(source, context.ipld, {
196+
...options,
197+
dagBuilder: async function * (source, ipld, options) {
198+
for await (const entry of source) {
199+
yield async function () {
200+
const cid = await persist(entry.content, ipld, options)
201+
202+
return {
203+
cid,
204+
path: entry.path,
205+
unixfs: UnixFS.unmarshal(entry.content.Data),
206+
node: entry.content
207+
}
208+
}
209+
}
210+
}
211+
}),
195212
(nodes) => last(nodes)
196213
)
197214

0 commit comments

Comments
 (0)