@@ -123,6 +123,28 @@ module.exports = (common) => {
123
123
} )
124
124
} )
125
125
126
+ it ( 'BIG buffer with progress' , ( done ) => {
127
+ const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
128
+
129
+ let progCount = 0
130
+ let progress = 0
131
+ const handler = ( p ) => {
132
+ progCount += 1
133
+ progress += p
134
+ }
135
+
136
+ ipfs . files . add ( bigFile , { progress : handler } , ( err , res ) => {
137
+ expect ( err ) . to . not . exist ( )
138
+ expect ( res ) . to . have . length ( 1 )
139
+ const file = res [ 0 ]
140
+ expect ( file . hash ) . to . equal ( expectedMultihash )
141
+ expect ( file . path ) . to . equal ( file . hash )
142
+ expect ( progCount ) . to . equal ( 58 )
143
+ expect ( progress ) . to . equal ( bigFile . byteLength )
144
+ done ( )
145
+ } )
146
+ } )
147
+
126
148
it ( 'add a nested dir as array' , ( done ) => {
127
149
// Needs https://github.com/ipfs/js-ipfs-api/issues/339 to be fixed
128
150
// for js-ipfs-api + go-ipfs
@@ -160,6 +182,56 @@ module.exports = (common) => {
160
182
} )
161
183
} )
162
184
185
+ it ( 'add a nested dir as array with progress' , ( done ) => {
186
+ // Needs https://github.com/ipfs/js-ipfs-api/issues/339 to be fixed
187
+ // for js-ipfs-api + go-ipfs
188
+ if ( ! isNode ) { return done ( ) }
189
+
190
+ const content = ( name ) => ( {
191
+ path : `test-folder/${ name } ` ,
192
+ content : directoryContent [ name ]
193
+ } )
194
+
195
+ const emptyDir = ( name ) => ( {
196
+ path : `test-folder/${ name } `
197
+ } )
198
+
199
+ const expectedRootMultihash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
200
+
201
+ const dirs = [
202
+ content ( 'pp.txt' ) ,
203
+ content ( 'holmes.txt' ) ,
204
+ content ( 'jungle.txt' ) ,
205
+ content ( 'alice.txt' ) ,
206
+ emptyDir ( 'empty-folder' ) ,
207
+ content ( 'files/hello.txt' ) ,
208
+ content ( 'files/ipfs.txt' ) ,
209
+ emptyDir ( 'files/empty' )
210
+ ]
211
+
212
+ const total = dirs . reduce ( ( i , entry ) => {
213
+ return i + ( entry . content ? entry . content . length : 0 )
214
+ } , 0 )
215
+
216
+ let progCount = 0
217
+ let progress = 0
218
+ const handler = ( p ) => {
219
+ progCount += 1
220
+ progress += p
221
+ }
222
+
223
+ ipfs . files . add ( dirs , { progress : handler } , ( err , res ) => {
224
+ expect ( err ) . to . not . exist ( )
225
+ const root = res [ res . length - 1 ]
226
+
227
+ expect ( root . path ) . to . equal ( 'test-folder' )
228
+ expect ( root . hash ) . to . equal ( expectedRootMultihash )
229
+ expect ( progCount ) . to . equal ( 8 )
230
+ expect ( progress ) . to . equal ( total )
231
+ done ( )
232
+ } )
233
+ } )
234
+
163
235
describe ( '.createAddStream' , ( ) => {
164
236
it ( 'stream of valid files and dirs' , ( done ) => {
165
237
const content = ( name ) => ( {
0 commit comments