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

Commit 605fec7

Browse files
author
Alan Shaw
committed
refactor: use CID v1 with base32 encoding by default
refs ipfs/js-ipfs#1440 License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent bc222c9 commit 605fec7

9 files changed

+102
-96
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"devDependencies": {
4040
"aegir": "^18.0.2",
4141
"chai": "^4.2.0",
42-
"cids": "~0.5.5",
42+
"cids": "github:ipld/js-cid#refactor/cidv1base32-default",
4343
"detect-node": "^2.0.4",
4444
"dirty-chai": "^2.0.1",
4545
"ipfs-unixfs-exporter": "~0.35.4",

src/builder/builder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const defaultOptions = {
2424
rawLeaves: false,
2525
hashAlg: 'sha2-256',
2626
leafType: 'file',
27-
cidVersion: 0,
27+
cidVersion: 1,
2828
progress: () => {}
2929
}
3030

src/importer/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ const defaultOptions = {
1515
chunker: 'fixed',
1616
rawLeaves: false,
1717
hashOnly: false,
18-
cidVersion: 0,
18+
cidVersion: 1,
1919
hash: null,
2020
leafType: 'file',
2121
hashAlg: 'sha2-256'
2222
}
2323

2424
module.exports = function (ipld, _options) {
2525
const options = Object.assign({}, defaultOptions, _options)
26-
options.cidVersion = options.cidVersion || 0
26+
options.cidVersion = options.cidVersion || 1
2727

28-
if (options.cidVersion > 0 && _options.rawLeaves === undefined) {
28+
if (options.cidVersion > 0 && (!_options || _options.rawLeaves === undefined)) {
2929
// if the cid version is 1 or above, use raw leaves as this is
3030
// what go does.
3131
options.rawLeaves = true

src/utils/persist.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
} = require('ipld-dag-pb')
88

99
const defaultOptions = {
10-
cidVersion: 0,
10+
cidVersion: 1,
1111
hashAlg: 'sha2-256',
1212
codec: 'dag-pb'
1313
}

test/builder-dir-sharding.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('builder: directory sharding', () => {
105105
expect(nodes[0].path).to.be.eql(expectedHash)
106106
expect(new CID(nodes[0].hash).toBaseEncodedString()).to.be.eql(expectedHash)
107107
expect(nodes[1].path).to.be.eql(expectedHash + '/b')
108-
expect(nodes[1].size).to.be.eql(29)
108+
expect(nodes[1].size).to.be.eql(21)
109109
} catch (err) {
110110
return done(err)
111111
}

test/hash-parity-with-go-ipfs.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const strategies = [
2121
]
2222

2323
const expectedHashes = {
24-
flat: 'QmRgXEDv6DL8uchf7h9j8hAGG8Fq5r1UZ6Jy3TQAPxEb76',
25-
balanced: 'QmVY1TFpjYKSo8LRG9oYgH4iy9AduwDvBGNhqap1Gkxme3',
26-
trickle: 'QmYPsm9oVGjWECkT7KikZmrf8imggqKe8uS8Jco3qfWUCH'
24+
flat: 'bafybeid7e25emp6ruqhuyrse2iwxd722gvb42hr6lycievs2sllafgk4fa',
25+
balanced: 'bafybeiehl4ol4wqhzzxouk4lqwjykqulpg4qvg4g24gntqbsqrqfs6rocu',
26+
trickle: 'bafybeihc3tgk6xojwmz7zl5kuzrigwcgnkxqd6dniiemohf4zemqnsqte4'
2727
}
2828

2929
strategies.forEach(strategy => {

test/import-export-nested-dir.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const importer = require('../src')
1616
const exporter = require('ipfs-unixfs-exporter')
1717

1818
describe('import and export: directory', () => {
19-
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK'
19+
const rootHash = 'bafybeig452tftu3cxeeynb76ihksupbmxt3uo2ypbqeyyg7ivy3ky7sqda'
2020
let ipld
2121

2222
before((done) => {
@@ -44,19 +44,19 @@ describe('import and export: directory', () => {
4444
expect(err).to.not.exist()
4545
expect(files.map(normalizeNode).sort(byPath)).to.be.eql([
4646
{ path: 'a/b/h',
47-
multihash: 'QmWHMpCtdNjemT2F3SjyrmnBXQXwEohaZd4apcbFBhbFRC' },
47+
multihash: 'bafkreihtuiwbz2hauwuwhe3qhadojlilmmbr6b4cygznq7orox6enkowhu' },
4848
{ path: 'a/b/g',
49-
multihash: 'QmQGwYzzTPcbqTiy2Nbp88gqqBqCWY4QZGfen45LFZkD5n' },
49+
multihash: 'bafkreicmwczfbrrfbvji6ptb2b6zocesc2g3nc576hvfxzfikhw2ienn7m' },
5050
{ path: 'a/b/c/d/f',
51-
multihash: 'QmNVHs2dy7AjGUotsubWVncRsD3SpRXm8MgmCCQTVdVACz' },
51+
multihash: 'bafkreic6on7yshnrc5kefi473zz6khlydjkfkbwxdskuo6tn5nmyrpl7ti' },
5252
{ path: 'a/b/c/d/e',
53-
multihash: 'QmYPbDKwc7oneCcEc6BcRSN5GXthTGWUCd19bTCyP9u3vH' },
53+
multihash: 'bafkreifuspkigzfp4rgrdqawlt2hbjawjupcmcmrd34zrpugrvdk3y66jy' },
5454
{ path: 'a/b/c/d',
55-
multihash: 'QmQGDXr3ysARM38n7h79Tx7yD3YxuzcnZ1naG71WMojPoj' },
55+
multihash: 'bafybeih327xgvrvrskzp2szg2h4mj2kppxubbb5go5dil2gdsqkdhctlga' },
5656
{ path: 'a/b/c',
57-
multihash: 'QmYTVcjYpN3hQLtJstCPE8hhEacAYjWAuTmmAAXoonamuE' },
57+
multihash: 'bafybeihepdheh6iqyrmwlcsuy4wbxsbbjqvqycs6eps5wqnsmdboqq5ow4' },
5858
{ path: 'a/b',
59-
multihash: 'QmWyWYxq1GD9fEyckf5LrJv8hMW35CwfWwzDBp8bTw3NQj' },
59+
multihash: 'bafybeieolgnh4uy6vp5wc5qij6ymhk3coh2mto4q57wmzzab3jfqfp66rq' },
6060
{ path: 'a',
6161
multihash: rootHash }
6262
])
@@ -87,13 +87,13 @@ describe('import and export: directory', () => {
8787
(err, files) => {
8888
expect(err).to.not.exist()
8989
expect(files.filter(fileHasContent).sort(byPath)).to.eql([
90-
{ path: 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/h',
90+
{ path: 'bafybeig452tftu3cxeeynb76ihksupbmxt3uo2ypbqeyyg7ivy3ky7sqda/b/h',
9191
content: 'cream' },
92-
{ path: 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/g',
92+
{ path: 'bafybeig452tftu3cxeeynb76ihksupbmxt3uo2ypbqeyyg7ivy3ky7sqda/b/g',
9393
content: 'ice' },
94-
{ path: 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c/d/f',
94+
{ path: 'bafybeig452tftu3cxeeynb76ihksupbmxt3uo2ypbqeyyg7ivy3ky7sqda/b/c/d/f',
9595
content: 'strawberry' },
96-
{ path: 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK/b/c/d/e',
96+
{ path: 'bafybeig452tftu3cxeeynb76ihksupbmxt3uo2ypbqeyyg7ivy3ky7sqda/b/c/d/e',
9797
content: 'banana' }
9898
])
9999
done()

test/importer.spec.js

+44-39
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ const smallFile = loadFixture('test/fixtures/200Bytes.txt')
3838
const baseFiles = {
3939
'200Bytes.txt': {
4040
path: '200Bytes.txt',
41-
multihash: 'QmQmZQxSKQppbsWfVzBvg59Cn3DKtsNVQ94bjAxg2h3Lb8',
41+
multihash: 'bafybeibeddt74r7hfsred3rupoyk7t3yqrnc6lq2tofkbjyeancgae7yc4',
4242
size: 211,
4343
name: '',
4444
leafSize: 200
4545
},
4646
'1.2MiB.txt': {
4747
path: '1.2MiB.txt',
48-
multihash: 'QmbPN6CXXWpejfQgnRYnMQcVYkFHEntHWqLNQjbkatYCh1',
49-
size: 1328062,
48+
multihash: 'bafybeidye343eoqqq6dbz75kytgafi4jwm2c7tybdlj2xvnj5epthnofmm',
49+
size: 1330520,
5050
name: '',
5151
leafSize: 1258000
5252
}
@@ -56,14 +56,14 @@ const strategyBaseFiles = {
5656
flat: baseFiles,
5757
balanced: extend({}, baseFiles, {
5858
'1.2MiB.txt': {
59-
multihash: 'QmeEGqUisUD2T6zU96PrZnCkHfXCGuQeGWKu4UoSuaZL3d',
60-
size: 1335420
59+
multihash: 'bafybeiaxcek2b4eedgyx4jjh4gquaof4beqemzz5ch4rmlsjsr67soz55q',
60+
size: 1338154
6161
}
6262
}),
6363
trickle: extend({}, baseFiles, {
6464
'1.2MiB.txt': {
65-
multihash: 'QmaiSohNUt1rBf2Lqz6ou54NHVPTbXbBoPuq9td4ekcBx4',
66-
size: 1334599
65+
multihash: 'bafybeicsszy6evjc47ldfasv2kh5wydapatazcuantf6nf6iwywftvggjq',
66+
size: 1337301
6767
}
6868
})
6969
}
@@ -78,39 +78,39 @@ const strategyOverrides = {
7878
balanced: {
7979
'foo-big': {
8080
path: 'foo-big',
81-
multihash: 'QmQ1S6eEamaf4t948etp8QiYQ9avrKCogiJnPRgNkVreLv',
82-
size: 1335478
81+
multihash: 'bafybeif7nmfq5sl7bvxi4o2kmqvpdri7l7jlgqe5xldeva2bz2xb64seky',
82+
size: 1338214
8383
},
8484
pim: {
85-
multihash: 'QmUpzaN4Jio2GB3HoPSRCMQD5EagdMWjSEGD4SGZXaCw7W',
86-
size: 1335744
85+
multihash: 'bafybeiaqfwmlhmlvftd7pe3d7fr2nuiwwvcd67zkh3p7u2vq6kg54sp36m',
86+
size: 1338482
8787
},
8888
'pam/pum': {
89-
multihash: 'QmUpzaN4Jio2GB3HoPSRCMQD5EagdMWjSEGD4SGZXaCw7W',
90-
size: 1335744
89+
multihash: 'bafybeiaqfwmlhmlvftd7pe3d7fr2nuiwwvcd67zkh3p7u2vq6kg54sp36m',
90+
size: 1338482
9191
},
9292
pam: {
93-
multihash: 'QmVoVD4fEWFLJLjvRCg4bGrziFhgECiaezp79AUfhuLgno',
94-
size: 2671269
93+
multihash: 'bafybeiheoaizzsupiyjc5t7l5cczonhf27f7zcoxsudfrphutnoomi7nxq',
94+
size: 2676745
9595
}
9696
},
9797
trickle: {
9898
'foo-big': {
9999
path: 'foo-big',
100-
multihash: 'QmPh6KSS7ghTqzgWhaoCiLoHFPF7HGqUxx7q9vcM5HUN4U',
101-
size: 1334657
100+
multihash: 'bafybeiauchq6pdjaf4nchxl7gtigktflzvlyiouemk3k5zdetzpbpgsoky',
101+
size: 1337361
102102
},
103103
pim: {
104-
multihash: 'QmPAn3G2x2nrq4A1fu2XUpwWtpqG4D1YXFDrU615NHvJbr',
105-
size: 1334923
104+
multihash: 'bafybeie3zigxtjsbyxpnhep74zofd5z6j52bpdzoxvptlr6syaqgxqcbui',
105+
size: 1337629
106106
},
107107
'pam/pum': {
108-
multihash: 'QmPAn3G2x2nrq4A1fu2XUpwWtpqG4D1YXFDrU615NHvJbr',
109-
size: 1334923
108+
multihash: 'bafybeie3zigxtjsbyxpnhep74zofd5z6j52bpdzoxvptlr6syaqgxqcbui',
109+
size: 1337629
110110
},
111111
pam: {
112-
multihash: 'QmZTJah1xpG9X33ZsPtDEi1tYSHGDqQMRHsGV5xKzAR2j4',
113-
size: 2669627
112+
multihash: 'bafybeifvnr4fzxothljw62c3cjicubsgasaxu6hsc6cwvh7opu4uaoh724',
113+
size: 2675039
114114
}
115115
}
116116
}
@@ -184,21 +184,21 @@ strategies.forEach((strategy) => {
184184
}),
185185
foo: {
186186
path: 'foo',
187-
multihash: 'QmQrb6KKWGo8w7zKfx2JksptY6wN7B2ysSBdKZr4xMU36d',
188-
size: 320
187+
multihash: 'bafybeiahadqxdlbf2w5l3bnyjmrso3zwlzeg6vcft7n6ogc3kgeg3eqcne',
188+
size: 324
189189
},
190190
'foo/bar': {
191191
path: 'foo/bar',
192-
multihash: 'Qmf5BQbTUyUAvd6Ewct83GYGnE1F6btiC3acLhR8MDxgkD',
193-
size: 270
192+
multihash: 'bafybeif2tllv3roheq754k4kbmlx3w6e36m3vntwe4apzufwd3aaqeqi5u',
193+
size: 272
194194
},
195195
'foo-big/1.2MiB.txt': extend({}, baseFiles['1.2MiB.txt'], {
196196
path: 'foo-big/1.2MiB.txt'
197197
}),
198198
'foo-big': {
199199
path: 'foo-big',
200-
multihash: 'Qma6JU3FoXU9eAzgomtmYPjzFBwVc2rRbECQpmHFiA98CJ',
201-
size: 1328120
200+
multihash: 'bafybeifmrcnmuli3vqni2gh5bzhq6dvn22kkpju6lak4xxjv7ut5m4qjxe',
201+
size: 1330580
202202
},
203203
'pim/200Bytes.txt': extend({}, baseFiles['200Bytes.txt'], {
204204
path: 'pim/200Bytes.txt'
@@ -208,24 +208,24 @@ strategies.forEach((strategy) => {
208208
}),
209209
pim: {
210210
path: 'pim',
211-
multihash: 'QmNk8VPGb3fkAQgoxctXo4Wmnr4PayFTASy4MiVXTtXqiA',
212-
size: 1328386
211+
multihash: 'bafybeih63r7unrizaqfpq6z337u3jh3m22ona552hpyqhdst3ign4ncnca',
212+
size: 1330848
213213
},
214214
'empty-dir': {
215215
path: 'empty-dir',
216-
multihash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
216+
multihash: 'bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354',
217217
size: 4
218218
},
219219
'pam/pum': {
220-
multihash: 'QmNk8VPGb3fkAQgoxctXo4Wmnr4PayFTASy4MiVXTtXqiA',
221-
size: 1328386
220+
multihash: 'bafybeih63r7unrizaqfpq6z337u3jh3m22ona552hpyqhdst3ign4ncnca',
221+
size: 1330848
222222
},
223223
pam: {
224-
multihash: 'QmPAixYTaYnPe795fcWcuRpo6tfwHgRKNiBHpMzoomDVN6',
225-
size: 2656553
224+
multihash: 'bafybeid2cwow7m4ii3523lzmippdhxpmc4qvmaezaftbo54xui662sidoa',
225+
size: 2661477
226226
},
227227
'200Bytes.txt with raw leaves': extend({}, baseFiles['200Bytes.txt'], {
228-
multihash: 'zb2rhXrz1gkCv8p4nUDZRohY6MzBE9C3HVTVDP72g6Du3SD9Q',
228+
multihash: 'bafkreiasdth246e2lufrhjpkdvud6yci622ouqgss3wou35reukddzlut4',
229229
size: 200
230230
})
231231
}, strategyOverrides[strategy])
@@ -241,7 +241,8 @@ strategies.forEach((strategy) => {
241241
maxChildrenPerNode: 10,
242242
chunkerOptions: {
243243
maxChunkSize: 1024
244-
}
244+
},
245+
rawLeaves: false
245246
}
246247

247248
before((done) => {
@@ -308,7 +309,7 @@ strategies.forEach((strategy) => {
308309
expect(nodes.length).to.be.eql(1)
309310

310311
// always yield empty node
311-
expect(new CID(nodes[0].multihash).toBaseEncodedString()).to.be.eql('QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH')
312+
expect(new CID(nodes[0].multihash).toBaseEncodedString()).to.be.eql('bafybeif7ztnhq65lumvvtr4ekcwd2ifwgm3awq4zfr3srh462rwyinlb4y')
312313
done()
313314
}))
314315
})
@@ -689,24 +690,28 @@ strategies.forEach((strategy) => {
689690

690691
it('imports file with raw leaf nodes when specified', (done) => {
691692
checkLeafNodeTypes(ipld, {
693+
rawLeaves: false,
692694
leafType: 'raw'
693695
}, 'raw', done)
694696
})
695697

696698
it('imports file with file leaf nodes when specified', (done) => {
697699
checkLeafNodeTypes(ipld, {
700+
rawLeaves: false,
698701
leafType: 'file'
699702
}, 'file', done)
700703
})
701704

702705
it('reduces file to single node when specified', (done) => {
703706
checkNodeLinks(ipld, {
707+
rawLeaves: false,
704708
reduceSingleLeafToSelf: true
705709
}, 0, done)
706710
})
707711

708712
it('does not reduce file to single node when overidden by options', (done) => {
709713
checkNodeLinks(ipld, {
714+
rawLeaves: false,
710715
reduceSingleLeafToSelf: false
711716
}, 1, done)
712717
})

0 commit comments

Comments
 (0)