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

chore: update deps and use cids instead of multihashes #224

Merged
merged 1 commit into from
Aug 8, 2018
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
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
"aegir": "^15.0.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"ipfs": "~0.30.1",
"ipfs": "~0.31.2",
"ipfs-block-service": "~0.14.0",
"ipfs-repo": "~0.22.1",
"multihashes": "~0.4.13",
"ncp": "^2.0.0",
"pull-generate": "^2.2.0",
"pull-zip": "^2.0.1",
Expand All @@ -51,15 +52,13 @@
},
"dependencies": {
"async": "^2.6.1",
"bs58": "^4.0.1",
"cids": "~0.5.3",
"deep-extend": "~0.6.0",
"ipfs-unixfs": "~0.1.15",
"ipld": "~0.17.2",
"ipld-dag-pb": "~0.14.5",
"ipld": "~0.17.3",
"ipld-dag-pb": "~0.14.6",
"left-pad": "^1.3.0",
"lodash": "^4.17.10",
"multihashes": "~0.4.13",
"multihashing-async": "~0.5.1",
"pull-batch": "^1.0.0",
"pull-block": "^1.4.0",
Expand Down
8 changes: 2 additions & 6 deletions src/exporter/clean-multihash.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'

const mh = require('multihashes')
const CID = require('cids')

module.exports = (multihash) => {
if (Buffer.isBuffer(multihash)) {
return mh.toB58String(multihash)
}

return multihash
return new CID(multihash).toBaseEncodedString()
}
10 changes: 5 additions & 5 deletions src/importer/flush-tree.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const mh = require('multihashes')
const UnixFS = require('ipfs-unixfs')
const CID = require('cids')
const dagPB = require('ipld-dag-pb')
Expand Down Expand Up @@ -86,7 +85,7 @@ function createSizeIndex (files) {
const sizeIndex = {}

files.forEach((file) => {
sizeIndex[mh.toB58String(file.multihash)] = file.size
sizeIndex[new CID(file.multihash).toBaseEncodedString()] = file.size
})

return sizeIndex
Expand Down Expand Up @@ -126,17 +125,18 @@ function traverse (tree, sizeIndex, path, ipld, source, done) {
const keys = Object.keys(tree)
const dir = new UnixFS('directory')
const links = keys.map((key) => {
const b58mh = mh.toB58String(tree[key])
const b58mh = new CID(tree[key]).toBaseEncodedString()
return new DAGLink(key, sizeIndex[b58mh], tree[key])
})

waterfall([
(cb) => DAGNode.create(dir.marshal(), links, cb),
(node, cb) => {
sizeIndex[mh.toB58String(node.multihash)] = node.size
const cid = new CID(node.multihash)
sizeIndex[cid.toBaseEncodedString()] = node.size

ipld.put(node, {
cid: new CID(node.multihash)
cid
}, (err) => cb(err, node))
}
], (err, node) => {
Expand Down
14 changes: 7 additions & 7 deletions test/builder-dir-sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const exporter = require('./../src').exporter
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const mh = require('multihashes')
const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const pull = require('pull-stream')
const pushable = require('pull-pushable')
const whilst = require('async/whilst')
const setImmediate = require('async/setImmediate')
const leftPad = require('left-pad')
const CID = require('cids')

module.exports = (repo) => {
describe('builder: directory sharding', function () {
Expand Down Expand Up @@ -87,9 +87,9 @@ module.exports = (repo) => {
pull.collect((err, nodes) => {
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
const expectedHash = mh.toB58String(nonShardedHash)
const expectedHash = new CID(nonShardedHash).toBaseEncodedString()
expect(nodes[0].path).to.be.eql(expectedHash)
expect(mh.toB58String(nodes[0].hash)).to.be.eql(expectedHash)
expect(new CID(nodes[0].hash).toBaseEncodedString()).to.be.eql(expectedHash)
expect(nodes[1].path).to.be.eql(expectedHash + '/b')
expect(nodes[1].size).to.be.eql(29)
pull(
Expand All @@ -113,7 +113,7 @@ module.exports = (repo) => {
pull.collect((err, nodes) => {
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(2)
const expectedHash = mh.toB58String(shardedHash)
const expectedHash = new CID(shardedHash).toBaseEncodedString()
expect(nodes[0].path).to.be.eql(expectedHash)
expect(nodes[0].hash).to.be.eql(expectedHash)
expect(nodes[1].path).to.be.eql(expectedHash + '/b')
Expand Down Expand Up @@ -209,7 +209,7 @@ module.exports = (repo) => {
function eachPath (path, index) {
if (!index) {
// first dir
expect(path).to.be.eql(mh.toB58String(rootHash))
expect(path).to.be.eql(new CID(rootHash).toBaseEncodedString())
const entry = entries[path]
expect(entry).to.exist()
expect(entry.content).to.not.exist()
Expand Down Expand Up @@ -315,7 +315,7 @@ module.exports = (repo) => {
if (!index) {
// first dir
if (depth === 1) {
expect(path).to.be.eql(mh.toB58String(rootHash))
expect(path).to.be.eql(new CID(rootHash).toBaseEncodedString())
}
const entry = entries[path]
expect(entry).to.exist()
Expand All @@ -338,7 +338,7 @@ module.exports = (repo) => {
})

it('exports a big dir with subpath', (done) => {
const exportHash = mh.toB58String(rootHash) + '/big/big/2000'
const exportHash = new CID(rootHash).toBaseEncodedString() + '/big/big/2000'
pull(
exporter(exportHash, ipld),
pull.collect(collected)
Expand Down
4 changes: 3 additions & 1 deletion test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ module.exports = (repo) => {
}, done)
})

it('allows multihash hash algorithm to be specified for big file', (done) => {
it('allows multihash hash algorithm to be specified for big file', function (done) {
this.timeout(30000)

eachSeries(testMultihashes, (hashAlg, cb) => {
const options = { hashAlg, strategy: 'flat' }
const content = String(Math.random() + Date.now())
Expand Down
7 changes: 2 additions & 5 deletions test/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const expect = chai.expect
const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const UnixFS = require('ipfs-unixfs')
const bs58 = require('bs58')
const pull = require('pull-stream')
const zip = require('pull-zip')
const CID = require('cids')
Expand Down Expand Up @@ -152,7 +151,6 @@ module.exports = (repo) => {

it('ensure hash inputs are sanitized', (done) => {
const hash = 'QmQmZQxSKQppbsWfVzBvg59Cn3DKtsNVQ94bjAxg2h3Lb8'
const mhBuf = Buffer.from(bs58.decode(hash))
const cid = new CID(hash)

ipld.get(cid, (err, result) => {
Expand All @@ -161,7 +159,7 @@ module.exports = (repo) => {
const unmarsh = UnixFS.unmarshal(node.data)

pull(
exporter(mhBuf, ipld),
exporter(cid, ipld),
pull.collect(onFiles)
)

Expand Down Expand Up @@ -444,8 +442,7 @@ module.exports = (repo) => {
exporter(files[0].multihash, ipld),
pull.collect((err, files) => {
expect(err).to.not.exist()

expect(bs58.encode(files[0].hash)).to.equal('QmQLTvhjmSa7657mKdSfTjxFBdwxmK8n9tZC9Xdp9DtxWY')
expect(new CID(files[0].hash).toBaseEncodedString()).to.equal('QmQLTvhjmSa7657mKdSfTjxFBdwxmK8n9tZC9Xdp9DtxWY')

fileEql(files[0], bigFile, done)
})
Expand Down
4 changes: 2 additions & 2 deletions test/hash-parity-with-go-ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const BlockService = require('ipfs-block-service')
const pull = require('pull-stream')
const mh = require('multihashes')
const CID = require('cids')
const Ipld = require('ipld')
const randomByteStream = require('./helpers/finite-pseudorandom-byte-stream')

Expand Down Expand Up @@ -53,7 +53,7 @@ module.exports = (repo) => {
expect(files.length).to.be.equal(1)

const file = files[0]
expect(mh.toB58String(file.multihash)).to.be.equal(expectedHashes[strategy])
expect(new CID(file.multihash).toBaseEncodedString()).to.be.equal(expectedHashes[strategy])
done()
})
)
Expand Down
4 changes: 2 additions & 2 deletions test/import-export-nested-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const expect = chai.expect
const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const pull = require('pull-stream')
const mh = require('multihashes')
const map = require('async/map')
const CID = require('cids')

const unixFSEngine = require('./../')

Expand Down Expand Up @@ -109,7 +109,7 @@ module.exports = (repo) => {
function normalizeNode (node) {
return {
path: node.path,
multihash: mh.toB58String(node.multihash)
multihash: new CID(node.multihash).toBaseEncodedString()
}
}

Expand Down
5 changes: 2 additions & 3 deletions test/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const expect = chai.expect
const spy = require('sinon/lib/sinon/spy')
const BlockService = require('ipfs-block-service')
const pull = require('pull-stream')
const mh = require('multihashes')
const CID = require('cids')
const Ipld = require('ipld')
const loadFixture = require('aegir/fixtures')
Expand All @@ -22,7 +21,7 @@ const collectLeafCids = require('./helpers/collect-leaf-cids')

function stringifyMh (files) {
return files.map((file) => {
file.multihash = mh.toB58String(file.multihash)
file.multihash = new CID(file.multihash).toBaseEncodedString()
return file
})
}
Expand Down Expand Up @@ -279,7 +278,7 @@ module.exports = (repo) => {
expect(nodes.length).to.be.eql(1)

// always yield empty node
expect(mh.toB58String(nodes[0].multihash)).to.be.eql('QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH')
expect(new CID(nodes[0].multihash).toBaseEncodedString()).to.be.eql('QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH')
done()
}))
})
Expand Down
6 changes: 3 additions & 3 deletions test/with-dag-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const pull = require('pull-stream')
const mh = require('multihashes')
const loadFixture = require('aegir/fixtures')
const IPFS = require('ipfs')
const os = require('os')
const path = require('path')
const CID = require('cids')

function stringifyMh (files) {
return files.map((file) => {
file.multihash = mh.toB58String(file.multihash)
file.multihash = new CID(file.multihash).toBaseEncodedString()
return file
})
}
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('with dag-api', function () {
expect(err).to.not.exist()
expect(nodes.length).to.be.eql(1)
// always yield empty node
expect(mh.toB58String(nodes[0].multihash)).to.be.eql('QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH')
expect(new CID(nodes[0].multihash).toBaseEncodedString()).to.be.eql('QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH')
done()
}))
})
Expand Down