@@ -256,40 +256,87 @@ describe('exporter sharded', function () {
256
256
expect ( exported . name ) . to . deep . equal ( 'file-1' )
257
257
} )
258
258
259
- it ( 'exports a shard with a different fanout size' , async ( ) => {
260
- const files : ImportCandidate [ ] = [ {
261
- path : '/baz.txt' ,
262
- content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
263
- } , {
264
- path : '/foo.txt' ,
265
- content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
266
- } , {
267
- path : '/bar.txt' ,
268
- content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
269
- } ]
259
+ describe ( 'alternate fanout size' , function ( ) {
260
+ it ( 'exports a shard with a fanout of 16' , async ( ) => {
261
+ const files : ImportCandidate [ ] = [ {
262
+ path : '/baz.txt' ,
263
+ content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
264
+ } , {
265
+ path : '/foo.txt' ,
266
+ content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
267
+ } , {
268
+ path : '/bar.txt' ,
269
+ content : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] )
270
+ } ]
270
271
271
- const result = await last ( importer ( files , block , {
272
- shardSplitThresholdBytes : 0 ,
273
- shardFanoutBits : 4 , // 2**4 = 16 children max
274
- wrapWithDirectory : true
275
- } ) )
272
+ const result = await last ( importer ( files , block , {
273
+ shardSplitThresholdBytes : 0 ,
274
+ shardFanoutBits : 4 , // 2**4 = 16 children max
275
+ wrapWithDirectory : true
276
+ } ) )
276
277
277
- if ( result == null ) {
278
- throw new Error ( 'Import failed' )
279
- }
278
+ if ( result == null ) {
279
+ throw new Error ( 'Import failed' )
280
+ }
280
281
281
- const { cid } = result
282
- const dir = await exporter ( cid , block )
282
+ const { cid } = result
283
+ const dir = await exporter ( cid , block )
284
+
285
+ expect ( dir ) . to . have . nested . property ( 'unixfs.fanout' , 16n )
286
+
287
+ const contents = await all ( dir . content ( ) )
283
288
284
- expect ( dir ) . to . have . nested . property ( 'unixfs.fanout' , 16n )
289
+ expect ( contents . map ( entry => ( {
290
+ path : `/${ entry . name } ` ,
291
+ content : entry . node
292
+ } ) ) )
293
+ . to . deep . equal ( files )
294
+ } )
295
+
296
+ // Cross-impl reference test: directory of files with single character
297
+ // names, starting from ' ' and ending with '~', but excluding the special
298
+ // characters '/' and '.'. Each file should contain a single byte with the
299
+ // same value as the character in its name. Files are added to a sharded
300
+ // directory with a fanout of 16, using CIDv1 throughout, and should result
301
+ // in the root CID of:
302
+ // bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44
303
+ it . only ( 'reference shard with fanout of 16' , async ( ) => {
304
+ const files : ImportCandidate [ ] = [ ]
305
+ for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= '~' . charCodeAt ( 0 ) ; ch ++ ) {
306
+ if ( ch == 47 || ch == 46 ) { // skip '/' and '.'
307
+ continue
308
+ }
309
+ files . push ( {
310
+ path : String . fromCharCode ( ch ) ,
311
+ content : Uint8Array . from ( [ ch ] )
312
+ } )
313
+ }
285
314
286
- const contents = await all ( dir . content ( ) )
315
+ const result = await last ( importer ( files , block , {
316
+ shardSplitThresholdBytes : 0 ,
317
+ shardFanoutBits : 4 ,
318
+ wrapWithDirectory : true
319
+ } ) )
287
320
288
- expect ( contents . map ( entry => ( {
289
- path : `/${ entry . name } ` ,
290
- content : entry . node
291
- } ) ) )
292
- . to . deep . equal ( files )
321
+ if ( result == null ) {
322
+ throw new Error ( 'Import failed' )
323
+ }
324
+
325
+ const { cid } = result
326
+ expect ( cid . toString ( ) ) . to . equal ( 'bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44' )
327
+
328
+ const dir = await exporter ( cid , block )
329
+
330
+ expect ( dir ) . to . have . nested . property ( 'unixfs.fanout' , 16n )
331
+
332
+ let contents = await all ( dir . content ( ) )
333
+ contents = contents . map ( entry => ( {
334
+ path : `${ entry . name } ` ,
335
+ content : entry . node
336
+ } ) )
337
+ contents . sort ( ( a , b ) => a . content [ 0 ] < b . content [ 0 ] ? - 1 : 1 )
338
+ expect ( contents ) . to . deep . equal ( files )
339
+ } )
293
340
} )
294
341
295
342
it ( 'walks path of a HAMT with a different fanout size' , async ( ) => {
0 commit comments