1
1
'use strict'
2
2
3
3
const {
4
- DAGLink,
5
- DAGNode
6
- } = require ( 'ipld-dag-pb' )
4
+ encode,
5
+ prepare
6
+ // @ts -ignore
7
+ } = require ( '@ipld/dag-pb' )
7
8
const UnixFS = require ( 'ipfs-unixfs' )
8
9
const Dir = require ( './dir' )
9
10
const persist = require ( './utils/persist' )
@@ -119,7 +120,11 @@ async function * flush (bucket, block, shardRoot, options) {
119
120
throw new Error ( 'Could not flush sharded directory, no subshard found' )
120
121
}
121
122
122
- links . push ( new DAGLink ( labelPrefix , shard . size , shard . cid ) )
123
+ links . push ( {
124
+ Name : labelPrefix ,
125
+ Tsize : shard . size ,
126
+ Hash : shard . cid
127
+ } )
123
128
childrenSize += shard . size
124
129
} else if ( typeof child . value . flush === 'function' ) {
125
130
const dir = child . value
@@ -132,7 +137,11 @@ async function * flush (bucket, block, shardRoot, options) {
132
137
}
133
138
134
139
const label = labelPrefix + child . key
135
- links . push ( new DAGLink ( label , flushedDir . size , flushedDir . cid ) )
140
+ links . push ( {
141
+ Name : label ,
142
+ Tsize : flushedDir . size ,
143
+ Hash : flushedDir . cid
144
+ } )
136
145
137
146
childrenSize += flushedDir . size
138
147
} else {
@@ -145,7 +154,11 @@ async function * flush (bucket, block, shardRoot, options) {
145
154
const label = labelPrefix + child . key
146
155
const size = value . size
147
156
148
- links . push ( new DAGLink ( label , size , value . cid ) )
157
+ links . push ( {
158
+ Name : label ,
159
+ Tsize : size ,
160
+ Hash : value . cid
161
+ } )
149
162
childrenSize += size
150
163
}
151
164
}
@@ -162,8 +175,11 @@ async function * flush (bucket, block, shardRoot, options) {
162
175
mode : shardRoot && shardRoot . mode
163
176
} )
164
177
165
- const node = new DAGNode ( dir . marshal ( ) , links )
166
- const buffer = node . serialize ( )
178
+ const node = {
179
+ Data : dir . marshal ( ) ,
180
+ Links : links
181
+ }
182
+ const buffer = encode ( prepare ( node ) )
167
183
const cid = await persist ( buffer , block , options )
168
184
const size = buffer . length + childrenSize
169
185
0 commit comments