@@ -56,10 +56,7 @@ describe('exporter', () => {
5656 type : options . type ,
5757 data : options . content
5858 } )
59- const node = {
60- Data : file . marshal ( ) ,
61- Links : options . links
62- }
59+ const node = dagPb . createNode ( file . marshal ( ) , options . links )
6360 const buf = dagPb . encode ( node )
6461 const cid = CID . createV0 ( await sha256 . digest ( buf ) )
6562 await block . put ( cid , buf )
@@ -147,19 +144,10 @@ describe('exporter', () => {
147144 const leaf = UnixFS . unmarshal ( child . node . Data )
148145
149146 file . addBlockSize ( leaf . fileSize ( ) )
150-
151- links . push ( {
152- Name : '' ,
153- Tsize : child . node . Data != null ? child . node . Data . length : 0 ,
154- Hash : child . cid
155- } )
156- }
157-
158- const node = {
159- Data : file . marshal ( ) ,
160- Links : links
147+ links . push ( dagPb . createLink ( '' , child . node . Data != null ? child . node . Data . length : 0 , child . cid ) )
161148 }
162149
150+ const node = dagPb . createNode ( file . marshal ( ) , links )
163151 const nodeBlock = dagPb . encode ( node )
164152 const nodeCid = CID . createV0 ( await sha256 . digest ( nodeBlock ) )
165153 await block . put ( nodeCid , nodeBlock )
@@ -265,19 +253,13 @@ describe('exporter', () => {
265253 type : 'raw' ,
266254 data : content . slice ( 0 , 5 )
267255 } )
268- const chunkNode1 = {
269- Data : chunk1 . marshal ( ) ,
270- Links : [ ]
271- }
256+ const chunkNode1 = dagPb . createNode ( chunk1 . marshal ( ) )
272257 const chunkBlock1 = dagPb . encode ( chunkNode1 )
273258 const chunkCid1 = CID . createV0 ( await sha256 . digest ( chunkBlock1 ) )
274259 await block . put ( chunkCid1 , chunkBlock1 )
275260
276261 const chunk2 = new UnixFS ( { type : 'raw' , data : content . slice ( 5 ) } )
277- const chunkNode2 = {
278- Data : chunk2 . marshal ( ) ,
279- Links : [ ]
280- }
262+ const chunkNode2 = dagPb . createNode ( chunk2 . marshal ( ) )
281263 const chunkBlock2 = dagPb . encode ( chunkNode2 )
282264 const chunkCid2 = CID . createV0 ( await sha256 . digest ( chunkBlock2 ) )
283265 await block . put ( chunkCid2 , chunkBlock2 )
@@ -288,18 +270,9 @@ describe('exporter', () => {
288270 file . addBlockSize ( 5 )
289271 file . addBlockSize ( 5 )
290272
291- const fileNode = dagPb . prepare ( {
292- Data : file . marshal ( ) ,
293- Links : [ {
294- Name : '' ,
295- Tsize : chunkNode1 . Data != null ? chunkNode1 . Data . length : 0 ,
296- Hash : chunkCid1 . toV0 ( )
297- } , {
298- Name : '' ,
299- Tsize : chunkNode2 . Data != null ? chunkNode2 . Data . length : 0 ,
300- Hash : chunkCid2 . toV0 ( )
301- } ]
302- } )
273+ const fileNode = dagPb . createNode ( file . marshal ( ) , [
274+ dagPb . createLink ( '' , chunkNode1 . Data != null ? chunkNode1 . Data . length : 0 , chunkCid1 . toV0 ( ) ) ,
275+ dagPb . createLink ( '' , chunkNode2 . Data != null ? chunkNode2 . Data . length : 0 , chunkCid2 . toV0 ( ) ) ] )
303276 const fileBlock = dagPb . encode ( fileNode )
304277 const fileCid = CID . createV0 ( await sha256 . digest ( fileBlock ) )
305278 await block . put ( fileCid , fileBlock )
@@ -321,11 +294,7 @@ describe('exporter', () => {
321294 const chunk = await dagPut ( { content : uint8ArrayConcat ( await all ( randomBytes ( 100 ) ) ) } )
322295 const result = await dagPut ( {
323296 content : uint8ArrayConcat ( await all ( randomBytes ( 100 ) ) ) ,
324- links : [ {
325- Name : '' ,
326- Tsize : chunk . node . Data != null ? chunk . node . Data . length : 0 ,
327- Hash : chunk . cid
328- } ]
297+ links : [ dagPb . createLink ( '' , chunk . node . Data != null ? chunk . node . Data . length : 0 , chunk . cid ) ]
329298 } )
330299
331300 if ( ! result . file . data ) {
@@ -1013,10 +982,7 @@ describe('exporter', () => {
1013982 } )
1014983
1015984 it ( 'errors we export a non-unixfs dag-pb node' , async ( ) => {
1016- const dagpbBlock = dagPb . encode ( {
1017- Data : Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] ) ,
1018- Links : [ ]
1019- } )
985+ const dagpbBlock = dagPb . encode ( dagPb . createNode ( Uint8Array . from ( [ 0 , 1 , 2 , 3 , 4 ] ) ) )
1020986 const dagpbCid = CID . createV0 ( await sha256 . digest ( dagpbBlock ) )
1021987 await block . put ( dagpbCid , dagpbBlock )
1022988
@@ -1037,14 +1003,8 @@ describe('exporter', () => {
10371003 } )
10381004 file . addBlockSize ( 100 )
10391005
1040- const dagpbBuffer = dagPb . encode ( {
1041- Data : file . marshal ( ) ,
1042- Links : [ {
1043- Name : '' ,
1044- Tsize : cborBlock . length ,
1045- Hash : cborCid
1046- } ]
1047- } )
1006+ const dagpbBuffer = dagPb . encode ( dagPb . createNode ( file . marshal ( ) ,
1007+ [ dagPb . createLink ( '' , cborBlock . length , cborCid ) ] ) )
10481008 const dagpbCid = CID . createV0 ( await sha256 . digest ( dagpbBuffer ) )
10491009 await block . put ( dagpbCid , dagpbBuffer )
10501010
0 commit comments