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

Commit b530f53

Browse files
committed
chore: address review comments
1 parent fdad329 commit b530f53

File tree

2 files changed

+60
-96
lines changed

2 files changed

+60
-96
lines changed

src/dir-hamt-sharded.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function shardedDirExporter (cid, node, name, path, pathRest, resolve, size, dag
8080
return addLinksToHamtBucket(node.links, options.lastBucket, options.rootBucket, cb)
8181
},
8282
(cb) => findPosition(targetFile, options.rootBucket, cb),
83-
({ position }, cb) => {
83+
(position, cb) => {
8484
let prefix = toPrefix(position.pos)
8585
const bucketPath = toBucketPath(position)
8686

@@ -191,7 +191,7 @@ const findPosition = (file, bucket, cb) => {
191191
return
192192
}
193193

194-
cb(null, { position })
194+
cb(null, position)
195195
})
196196
}
197197

test/exporter-sharded.spec.js

+58-94
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('exporter sharded', function () {
8585
wrap: true,
8686
shardSplitThreshold: SHARD_SPLIT_THRESHOLD
8787
}),
88-
pull.collect(cb)
88+
collect(cb)
8989
),
9090
(imported, cb) => {
9191
directory = new CID(imported.pop().multihash)
@@ -104,7 +104,7 @@ describe('exporter sharded', function () {
104104

105105
pull(
106106
exporter(directory, ipld),
107-
pull.collect(cb)
107+
collect(cb)
108108
)
109109
},
110110
(exported, cb) => {
@@ -117,7 +117,7 @@ describe('exporter sharded', function () {
117117
exported.map(exported => (cb) => {
118118
pull(
119119
exported.content,
120-
pull.collect((err, bufs) => {
120+
collect((err, bufs) => {
121121
if (err) {
122122
cb(err)
123123
}
@@ -160,7 +160,7 @@ describe('exporter sharded', function () {
160160
wrap: true,
161161
shardSplitThreshold: SHARD_SPLIT_THRESHOLD
162162
}),
163-
pull.collect(cb)
163+
collect(cb)
164164
),
165165
(imported, cb) => {
166166
dirCid = new CID(imported.pop().multihash)
@@ -169,7 +169,7 @@ describe('exporter sharded', function () {
169169
exporter(dirCid, ipld, {
170170
maxDepth: 1
171171
}),
172-
pull.collect(cb)
172+
collect(cb)
173173
)
174174
},
175175
(exported, cb) => {
@@ -189,23 +189,19 @@ describe('exporter sharded', function () {
189189
(dir, cb) => {
190190
pull(
191191
exporter(`/ipfs/${dir.toBaseEncodedString()}`, ipld),
192-
pull.collect(cb)
192+
collect(cb)
193193
)
194194
},
195195
(exported, cb) => {
196-
try {
197-
expect(exported.length).to.equal(32)
196+
expect(exported.length).to.equal(32)
198197

199-
const dir = exported.shift()
198+
const dir = exported.shift()
200199

201-
expect(dir.type).to.equal('dir')
200+
expect(dir.type).to.equal('dir')
202201

203-
exported.forEach(file => expect(file.type).to.equal('file'))
202+
exported.forEach(file => expect(file.type).to.equal('file'))
204203

205-
cb()
206-
} catch (e) {
207-
cb(e)
208-
}
204+
cb()
209205
}
210206
], done)
211207
})
@@ -216,21 +212,17 @@ describe('exporter sharded', function () {
216212
(dir, cb) => {
217213
pull(
218214
exporter(`/ipfs/${dir.toBaseEncodedString()}/file-14`, ipld),
219-
pull.collect(cb)
215+
collect(cb)
220216
)
221217
},
222218
(exported, cb) => {
223-
try {
224-
expect(exported.length).to.equal(1)
219+
expect(exported.length).to.equal(1)
225220

226-
const file = exported.shift()
221+
const file = exported.shift()
227222

228-
expect(file.name).to.deep.equal('file-14')
223+
expect(file.name).to.deep.equal('file-14')
229224

230-
cb()
231-
} catch (e) {
232-
cb(e)
233-
}
225+
cb()
234226
}
235227
], done)
236228
})
@@ -241,21 +233,17 @@ describe('exporter sharded', function () {
241233
(dir, cb) => {
242234
pull(
243235
exporter(`/ipfs/${dir.toBaseEncodedString()}/file-30`, ipld),
244-
pull.collect(cb)
236+
collect(cb)
245237
)
246238
},
247239
(exported, cb) => {
248-
try {
249-
expect(exported.length).to.equal(1)
240+
expect(exported.length).to.equal(1)
250241

251-
const file = exported.shift()
242+
const file = exported.shift()
252243

253-
expect(file.name).to.deep.equal('file-30')
244+
expect(file.name).to.deep.equal('file-30')
254245

255-
cb()
256-
} catch (e) {
257-
cb(e)
258-
}
246+
cb()
259247
}
260248
], done)
261249
})
@@ -266,21 +254,17 @@ describe('exporter sharded', function () {
266254
(dir, cb) => {
267255
pull(
268256
exporter(`/ipfs/${dir.toBaseEncodedString()}/file-2567`, ipld),
269-
pull.collect(cb)
257+
collect(cb)
270258
)
271259
},
272260
(exported, cb) => {
273-
try {
274-
expect(exported.length).to.equal(1)
261+
expect(exported.length).to.equal(1)
275262

276-
const file = exported.shift()
263+
const file = exported.shift()
277264

278-
expect(file.name).to.deep.equal('file-2567')
265+
expect(file.name).to.deep.equal('file-2567')
279266

280-
cb()
281-
} catch (e) {
282-
cb(e)
283-
}
267+
cb()
284268
}
285269
], done)
286270
})
@@ -293,21 +277,17 @@ describe('exporter sharded', function () {
293277
exporter(`/ipfs/${dir.toBaseEncodedString()}/foo/bar/baz`, ipld, {
294278
maxDepth: 3
295279
}),
296-
pull.collect(cb)
280+
collect(cb)
297281
)
298282
},
299283
(exported, cb) => {
300-
try {
301-
expect(exported.length).to.equal(1)
284+
expect(exported.length).to.equal(1)
302285

303-
const entry = exported.pop()
286+
const entry = exported.pop()
304287

305-
expect(entry.name).to.deep.equal('baz')
288+
expect(entry.name).to.deep.equal('baz')
306289

307-
cb()
308-
} catch (e) {
309-
cb(e)
310-
}
290+
cb()
311291
}
312292
], done)
313293
})
@@ -320,21 +300,17 @@ describe('exporter sharded', function () {
320300
exporter(`/ipfs/${dir.toBaseEncodedString()}/foo/bar/baz`, ipld, {
321301
maxDepth: 2
322302
}),
323-
pull.collect(cb)
303+
collect(cb)
324304
)
325305
},
326306
(exported, cb) => {
327-
try {
328-
expect(exported.length).to.equal(1)
307+
expect(exported.length).to.equal(1)
329308

330-
const entry = exported.pop()
309+
const entry = exported.pop()
331310

332-
expect(entry.name).to.deep.equal('bar')
311+
expect(entry.name).to.deep.equal('bar')
333312

334-
cb()
335-
} catch (e) {
336-
cb(e)
337-
}
313+
cb()
338314
}
339315
], done)
340316
})
@@ -347,22 +323,18 @@ describe('exporter sharded', function () {
347323
exporter(`/ipfs/${dir.toBaseEncodedString()}/foo/bar/baz/file-1`, ipld, {
348324
fullPath: true
349325
}),
350-
pull.collect(cb)
326+
collect(cb)
351327
)
352328
},
353329
(exported, cb) => {
354-
try {
355-
expect(exported.length).to.equal(5)
356-
357-
expect(exported[1].name).to.equal('foo')
358-
expect(exported[2].name).to.equal('bar')
359-
expect(exported[3].name).to.equal('baz')
360-
expect(exported[4].name).to.equal('file-1')
361-
362-
cb()
363-
} catch (e) {
364-
cb(e)
365-
}
330+
expect(exported.length).to.equal(5)
331+
332+
expect(exported[1].name).to.equal('foo')
333+
expect(exported[2].name).to.equal('bar')
334+
expect(exported[3].name).to.equal('baz')
335+
expect(exported[4].name).to.equal('file-1')
336+
337+
cb()
366338
}
367339
], done)
368340
})
@@ -375,24 +347,20 @@ describe('exporter sharded', function () {
375347
exporter(`/ipfs/${dir.toBaseEncodedString()}/foo/bar/baz`, ipld, {
376348
fullPath: true
377349
}),
378-
pull.collect(cb)
350+
collect(cb)
379351
)
380352
},
381353
(exported, cb) => {
382-
try {
383-
expect(exported.length).to.equal(35)
354+
expect(exported.length).to.equal(35)
384355

385-
expect(exported[1].name).to.equal('foo')
386-
expect(exported[2].name).to.equal('bar')
387-
expect(exported[3].name).to.equal('baz')
388-
expect(exported[4].name).to.equal('file-14')
356+
expect(exported[1].name).to.equal('foo')
357+
expect(exported[2].name).to.equal('bar')
358+
expect(exported[3].name).to.equal('baz')
359+
expect(exported[4].name).to.equal('file-14')
389360

390-
exported.slice(4).forEach(file => expect(file.type).to.equal('file'))
361+
exported.slice(4).forEach(file => expect(file.type).to.equal('file'))
391362

392-
cb()
393-
} catch (e) {
394-
cb(e)
395-
}
363+
cb()
396364
}
397365
], done)
398366
})
@@ -427,21 +395,17 @@ describe('exporter sharded', function () {
427395
(dir, cb) => {
428396
pull(
429397
exporter(`/ipfs/${dir.toBaseEncodedString()}/normal-dir/shard/file-1`, ipld),
430-
pull.collect(cb)
398+
collect(cb)
431399
)
432400
},
433401
(exported, cb) => {
434-
try {
435-
expect(exported.length).to.equal(1)
402+
expect(exported.length).to.equal(1)
436403

437-
const entry = exported.pop()
404+
const entry = exported.pop()
438405

439-
expect(entry.name).to.deep.equal('file-1')
406+
expect(entry.name).to.deep.equal('file-1')
440407

441-
cb()
442-
} catch (e) {
443-
cb(e)
444-
}
408+
cb()
445409
}
446410
], done)
447411
})

0 commit comments

Comments
 (0)