Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: use unixfs exporter with CID instances
Browse files Browse the repository at this point in the history
Allows IPFS to use the unixfs exporter that exports CID instances _without_ API changes.

refs ipfs-inactive/interface-js-ipfs-core#394

Depends on:

* [ ] ipfs-inactive/js-ipfs-mfs#44
* [ ] ipfs-inactive/js-ipfs-unixfs-exporter#19

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
alanshaw committed Mar 18, 2019
1 parent ff8cb2f commit 723fd0f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^30.0.0",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.9.1",
"ipfs-mfs": "github:ipfs/js-ipfs-mfs#refactor/use-exporter-w-cid-instances",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.26.1",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.35.3",
"ipfs-unixfs-exporter": "github:ipfs/js-ipfs-unixfs-exporter#refactor/export-cid-instances",
"ipfs-unixfs-importer": "~0.38.4",
"ipld": "~0.21.1",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-pb": "~0.15.3",
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/files-regular/add-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { importer } = require('ipfs-unixfs-engine')
const importer = require('ipfs-unixfs-importer')
const pull = require('pull-stream')
const toPull = require('stream-to-pull-stream')
const waterfall = require('async/waterfall')
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/files-regular/cat-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { exporter } = require('ipfs-unixfs-engine')
const exporter = require('ipfs-unixfs-exporter')
const pull = require('pull-stream')
const deferred = require('pull-defer')
const { normalizePath } = require('./utils')
Expand Down
7 changes: 5 additions & 2 deletions src/core/components/files-regular/get-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { exporter } = require('ipfs-unixfs-engine')
const exporter = require('ipfs-unixfs-exporter')
const pull = require('pull-stream')
const errCode = require('err-code')
const { normalizePath } = require('./utils')
Expand All @@ -21,6 +21,9 @@ module.exports = function (self) {
self._preload(pathComponents[0])
}

return exporter(ipfsPath, self._ipld, options)
return pull(
exporter(ipfsPath, self._ipld, options),
pull.map(file => Object.assign(file, { hash: file.cid.toString() }))
)
}
}
5 changes: 2 additions & 3 deletions src/core/components/files-regular/ls-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const { exporter } = require('ipfs-unixfs-engine')
const exporter = require('ipfs-unixfs-exporter')
const pull = require('pull-stream')
const CID = require('cids')
const { normalizePath } = require('./utils')

module.exports = function (self) {
Expand All @@ -26,7 +25,7 @@ module.exports = function (self) {
recursive ? node.depth >= pathDepth : node.depth === pathDepth
),
pull.map(node => {
node.hash = new CID(node.hash).toBaseEncodedString()
node.hash = node.cid.toString()
delete node.content
return node
})
Expand Down
5 changes: 2 additions & 3 deletions src/http/api/resources/file.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const isIpfs = require('is-ipfs')
const unixfsEngine = require('ipfs-unixfs-engine')
const exporter = unixfsEngine.exporter
const exporter = require('ipfs-unixfs-exporter')
const pull = require('pull-stream')
const toB58String = require('multihashes').toB58String
const Boom = require('boom')
Expand Down Expand Up @@ -82,7 +81,7 @@ exports.ls = {
const links = []
files.forEach((file) => {
if (file.depth === rootDepth) {
const id = toB58String(file.hash)
const id = file.cid.toString()
res.Arguments[path] = id
res.Objects[id] = toFileObject(file)
res.Objects[id].Links = file.type === 'file' ? null : links
Expand Down

0 comments on commit 723fd0f

Please sign in to comment.