@@ -200,6 +200,171 @@ test('should getPath on file with carScope=file', async t => {
200
200
t . deepEqual ( blocks . at ( 3 ) . bytes , filePart2 . bytes )
201
201
} )
202
202
203
+ test ( 'should getPath on large file with carScope=file, default ordering' , async t => {
204
+ // return all blocks in path and all blocks for resolved target of path
205
+ const filePart1 = await Block . decode ( { codec : raw , bytes : fromString ( `MORE TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
206
+ const filePart2 = await Block . decode ( { codec : raw , bytes : fromString ( `EVEN MORE TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
207
+ const filePart3 = await Block . decode ( { codec : raw , bytes : fromString ( `SO MUCH TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
208
+ const filePart4 = await Block . decode ( { codec : raw , bytes : fromString ( `TEST DATA DOING THE MOST ${ Date . now ( ) } ` ) , hasher : sha256 } )
209
+ const fileSubNode1 = await Block . encode ( {
210
+ codec : dagPB ,
211
+ hasher : sha256 ,
212
+ value : {
213
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
214
+ Links : [
215
+ { Name : '0' , Hash : filePart1 . cid } ,
216
+ { Name : '1' , Hash : filePart2 . cid }
217
+ ]
218
+ }
219
+ } )
220
+ const fileSubNode2 = await Block . encode ( {
221
+ codec : dagPB ,
222
+ hasher : sha256 ,
223
+ value : {
224
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
225
+ Links : [
226
+ { Name : '0' , Hash : filePart3 . cid } ,
227
+ { Name : '1' , Hash : filePart4 . cid }
228
+ ]
229
+ }
230
+ } )
231
+
232
+ const fileNode = await Block . encode ( {
233
+ codec : dagPB ,
234
+ hasher : sha256 ,
235
+ value : {
236
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
237
+ Links : [
238
+ { Name : '0' , Hash : fileSubNode1 . cid } ,
239
+ { Name : '1' , Hash : fileSubNode2 . cid }
240
+ ]
241
+ }
242
+ } )
243
+
244
+ const dirNode = await Block . encode ( {
245
+ codec : dagPB ,
246
+ hasher : sha256 ,
247
+ value : {
248
+ Data : new UnixFSv1 ( { type : 'directory' } ) . marshal ( ) ,
249
+ Links : [
250
+ { Name : 'foo' , Hash : fileNode . cid } ,
251
+ { Name : 'other' , Hash : CID . parse ( 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ) }
252
+ ]
253
+ }
254
+ } )
255
+
256
+ const peer = await startBitswapPeer ( [ filePart1 , filePart2 , filePart3 , filePart4 , fileSubNode1 , fileSubNode2 , fileNode , dirNode ] )
257
+
258
+ const libp2p = await getLibp2p ( )
259
+ const dagula = await fromNetwork ( libp2p , { peer : peer . libp2p . getMultiaddrs ( ) [ 0 ] } )
260
+
261
+ const blocks = [ ]
262
+ const carScope = 'file'
263
+ for await ( const entry of dagula . getPath ( `${ dirNode . cid } /foo` , { carScope } ) ) {
264
+ blocks . push ( entry )
265
+ }
266
+ // did not try and return block for `other`
267
+ t . is ( blocks . length , 8 )
268
+ t . deepEqual ( blocks . at ( 0 ) . cid , dirNode . cid )
269
+ t . deepEqual ( blocks . at ( 0 ) . bytes , dirNode . bytes )
270
+ t . deepEqual ( blocks . at ( 1 ) . cid , fileNode . cid )
271
+ t . deepEqual ( blocks . at ( 1 ) . bytes , fileNode . bytes )
272
+ t . deepEqual ( blocks . at ( 2 ) . cid , fileSubNode1 . cid )
273
+ t . deepEqual ( blocks . at ( 2 ) . bytes , fileSubNode1 . bytes )
274
+ t . deepEqual ( blocks . at ( 3 ) . cid , fileSubNode2 . cid )
275
+ t . deepEqual ( blocks . at ( 3 ) . bytes , fileSubNode2 . bytes )
276
+ t . deepEqual ( blocks . at ( 4 ) . cid , filePart1 . cid )
277
+ t . deepEqual ( blocks . at ( 4 ) . bytes , filePart1 . bytes )
278
+ t . deepEqual ( blocks . at ( 5 ) . cid , filePart2 . cid )
279
+ t . deepEqual ( blocks . at ( 5 ) . bytes , filePart2 . bytes )
280
+ t . deepEqual ( blocks . at ( 6 ) . cid , filePart3 . cid )
281
+ t . deepEqual ( blocks . at ( 6 ) . bytes , filePart3 . bytes )
282
+ t . deepEqual ( blocks . at ( 7 ) . cid , filePart4 . cid )
283
+ t . deepEqual ( blocks . at ( 7 ) . bytes , filePart4 . bytes )
284
+ } )
285
+
286
+ test ( 'should getPath on large file with carScope=file, dfs ordering' , async t => {
287
+ // return all blocks in path and all blocks for resolved target of path
288
+ const filePart1 = await Block . decode ( { codec : raw , bytes : fromString ( `MORE TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
289
+ const filePart2 = await Block . decode ( { codec : raw , bytes : fromString ( `EVEN MORE TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
290
+ const filePart3 = await Block . decode ( { codec : raw , bytes : fromString ( `SO MUCH TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
291
+ const filePart4 = await Block . decode ( { codec : raw , bytes : fromString ( `TEST DATA DOING THE MOST ${ Date . now ( ) } ` ) , hasher : sha256 } )
292
+ const fileSubNode1 = await Block . encode ( {
293
+ codec : dagPB ,
294
+ hasher : sha256 ,
295
+ value : {
296
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
297
+ Links : [
298
+ { Name : '0' , Hash : filePart1 . cid } ,
299
+ { Name : '1' , Hash : filePart2 . cid }
300
+ ]
301
+ }
302
+ } )
303
+ const fileSubNode2 = await Block . encode ( {
304
+ codec : dagPB ,
305
+ hasher : sha256 ,
306
+ value : {
307
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
308
+ Links : [
309
+ { Name : '0' , Hash : filePart3 . cid } ,
310
+ { Name : '1' , Hash : filePart4 . cid }
311
+ ]
312
+ }
313
+ } )
314
+
315
+ const fileNode = await Block . encode ( {
316
+ codec : dagPB ,
317
+ hasher : sha256 ,
318
+ value : {
319
+ Data : new UnixFSv1 ( { type : 'file' } ) . marshal ( ) ,
320
+ Links : [
321
+ { Name : '0' , Hash : fileSubNode1 . cid } ,
322
+ { Name : '1' , Hash : fileSubNode2 . cid }
323
+ ]
324
+ }
325
+ } )
326
+
327
+ const dirNode = await Block . encode ( {
328
+ codec : dagPB ,
329
+ hasher : sha256 ,
330
+ value : {
331
+ Data : new UnixFSv1 ( { type : 'directory' } ) . marshal ( ) ,
332
+ Links : [
333
+ { Name : 'foo' , Hash : fileNode . cid } ,
334
+ { Name : 'other' , Hash : CID . parse ( 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' ) }
335
+ ]
336
+ }
337
+ } )
338
+
339
+ const peer = await startBitswapPeer ( [ filePart1 , filePart2 , filePart3 , filePart4 , fileSubNode1 , fileSubNode2 , fileNode , dirNode ] )
340
+
341
+ const libp2p = await getLibp2p ( )
342
+ const dagula = await fromNetwork ( libp2p , { peer : peer . libp2p . getMultiaddrs ( ) [ 0 ] } )
343
+
344
+ const blocks = [ ]
345
+ const carScope = 'file'
346
+ for await ( const entry of dagula . getPath ( `${ dirNode . cid } /foo` , { carScope, order : 'dfs' } ) ) {
347
+ blocks . push ( entry )
348
+ }
349
+ // did not try and return block for `other`
350
+ t . is ( blocks . length , 8 )
351
+ t . deepEqual ( blocks . at ( 0 ) . cid , dirNode . cid )
352
+ t . deepEqual ( blocks . at ( 0 ) . bytes , dirNode . bytes )
353
+ t . deepEqual ( blocks . at ( 1 ) . cid , fileNode . cid )
354
+ t . deepEqual ( blocks . at ( 1 ) . bytes , fileNode . bytes )
355
+ t . deepEqual ( blocks . at ( 2 ) . cid , fileSubNode1 . cid )
356
+ t . deepEqual ( blocks . at ( 2 ) . bytes , fileSubNode1 . bytes )
357
+ t . deepEqual ( blocks . at ( 3 ) . cid , filePart1 . cid )
358
+ t . deepEqual ( blocks . at ( 3 ) . bytes , filePart1 . bytes )
359
+ t . deepEqual ( blocks . at ( 4 ) . cid , filePart2 . cid )
360
+ t . deepEqual ( blocks . at ( 4 ) . bytes , filePart2 . bytes )
361
+ t . deepEqual ( blocks . at ( 5 ) . cid , fileSubNode2 . cid )
362
+ t . deepEqual ( blocks . at ( 5 ) . bytes , fileSubNode2 . bytes )
363
+ t . deepEqual ( blocks . at ( 6 ) . cid , filePart3 . cid )
364
+ t . deepEqual ( blocks . at ( 6 ) . bytes , filePart3 . bytes )
365
+ t . deepEqual ( blocks . at ( 7 ) . cid , filePart4 . cid )
366
+ t . deepEqual ( blocks . at ( 7 ) . bytes , filePart4 . bytes )
367
+ } )
203
368
test ( 'should getPath on file with carScope=block' , async t => {
204
369
// return all blocks in path and all blocks for resolved target of path
205
370
const filePart1 = await Block . decode ( { codec : raw , bytes : fromString ( `MORE TEST DATA ${ Date . now ( ) } ` ) , hasher : sha256 } )
0 commit comments