@@ -56,10 +56,7 @@ describe('exporter', () => {
56
56
type : options . type ,
57
57
data : options . content
58
58
} )
59
- const node = {
60
- Data : file . marshal ( ) ,
61
- Links : options . links
62
- }
59
+ const node = dagPb . createNode ( file . marshal ( ) , options . links )
63
60
const buf = dagPb . encode ( node )
64
61
const cid = CID . createV0 ( await sha256 . digest ( buf ) )
65
62
await block . put ( cid , buf )
@@ -147,19 +144,10 @@ describe('exporter', () => {
147
144
const leaf = UnixFS . unmarshal ( child . node . Data )
148
145
149
146
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 ) )
161
148
}
162
149
150
+ const node = dagPb . createNode ( file . marshal ( ) , links )
163
151
const nodeBlock = dagPb . encode ( node )
164
152
const nodeCid = CID . createV0 ( await sha256 . digest ( nodeBlock ) )
165
153
await block . put ( nodeCid , nodeBlock )
@@ -265,19 +253,13 @@ describe('exporter', () => {
265
253
type : 'raw' ,
266
254
data : content . slice ( 0 , 5 )
267
255
} )
268
- const chunkNode1 = {
269
- Data : chunk1 . marshal ( ) ,
270
- Links : [ ]
271
- }
256
+ const chunkNode1 = dagPb . createNode ( chunk1 . marshal ( ) )
272
257
const chunkBlock1 = dagPb . encode ( chunkNode1 )
273
258
const chunkCid1 = CID . createV0 ( await sha256 . digest ( chunkBlock1 ) )
274
259
await block . put ( chunkCid1 , chunkBlock1 )
275
260
276
261
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 ( ) )
281
263
const chunkBlock2 = dagPb . encode ( chunkNode2 )
282
264
const chunkCid2 = CID . createV0 ( await sha256 . digest ( chunkBlock2 ) )
283
265
await block . put ( chunkCid2 , chunkBlock2 )
@@ -288,18 +270,9 @@ describe('exporter', () => {
288
270
file . addBlockSize ( 5 )
289
271
file . addBlockSize ( 5 )
290
272
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 ( ) ) ] )
303
276
const fileBlock = dagPb . encode ( fileNode )
304
277
const fileCid = CID . createV0 ( await sha256 . digest ( fileBlock ) )
305
278
await block . put ( fileCid , fileBlock )
@@ -321,11 +294,7 @@ describe('exporter', () => {
321
294
const chunk = await dagPut ( { content : uint8ArrayConcat ( await all ( randomBytes ( 100 ) ) ) } )
322
295
const result = await dagPut ( {
323
296
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 ) ]
329
298
} )
330
299
331
300
if ( ! result . file . data ) {
@@ -1013,10 +982,7 @@ describe('exporter', () => {
1013
982
} )
1014
983
1015
984
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 ] ) ) )
1020
986
const dagpbCid = CID . createV0 ( await sha256 . digest ( dagpbBlock ) )
1021
987
await block . put ( dagpbCid , dagpbBlock )
1022
988
@@ -1037,14 +1003,8 @@ describe('exporter', () => {
1037
1003
} )
1038
1004
file . addBlockSize ( 100 )
1039
1005
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 ) ] ) )
1048
1008
const dagpbCid = CID . createV0 ( await sha256 . digest ( dagpbBuffer ) )
1049
1009
await block . put ( dagpbCid , dagpbBuffer )
1050
1010
0 commit comments