@@ -6,13 +6,12 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha')
6
6
const loadFixture = require ( 'aegir/fixtures' )
7
7
const mh = require ( 'multihashes' )
8
8
const CID = require ( 'cids' )
9
- const values = require ( 'pull-stream/sources/values ' )
10
- const pull = require ( 'pull-stream/pull ' )
11
- const collect = require ( 'pull-stream/sinks/collect ' )
9
+ const all = require ( 'it-all ' )
10
+ const pipe = require ( 'it-pipe ' )
11
+ const { TimeoutError } = require ( 'ky-universal ' )
12
12
13
13
const ipfsClient = require ( '../src' )
14
14
const f = require ( './utils/factory' )
15
- const expectTimeout = require ( './utils/expect-timeout' )
16
15
17
16
const testfile = loadFixture ( 'test/fixtures/testfile.txt' )
18
17
@@ -53,7 +52,7 @@ describe('.files (the MFS API part)', function () {
53
52
} )
54
53
55
54
it ( '.add file for testing' , async ( ) => {
56
- const res = await ipfs . add ( testfile )
55
+ const res = await all ( ipfs . add ( testfile ) )
57
56
58
57
expect ( res ) . to . have . length ( 1 )
59
58
expect ( res [ 0 ] . hash ) . to . equal ( expectedMultihash )
@@ -66,7 +65,7 @@ describe('.files (the MFS API part)', function () {
66
65
const expectedBufferMultihash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX'
67
66
const file = Buffer . from ( 'hello' )
68
67
69
- const res = await ipfs . add ( file )
68
+ const res = await all ( ipfs . add ( file ) )
70
69
71
70
expect ( res ) . to . have . length ( 1 )
72
71
expect ( res [ 0 ] . hash ) . to . equal ( expectedBufferMultihash )
@@ -77,7 +76,7 @@ describe('.files (the MFS API part)', function () {
77
76
const expectedHash = 'QmWfVY9y3xjsixTgbd9AorQxH7VtMpzfx2HaWtsoUYecaX'
78
77
const content = Buffer . from ( 'hello' )
79
78
80
- const res = await ipfs . add ( [ { path : '' , content } ] )
79
+ const res = await all ( ipfs . add ( [ { path : '' , content } ] ) )
81
80
82
81
expect ( res ) . to . have . length ( 1 )
83
82
expect ( res [ 0 ] . hash ) . to . equal ( expectedHash )
@@ -88,7 +87,7 @@ describe('.files (the MFS API part)', function () {
88
87
const expectedCid = 'bafybeifogzovjqrcxvgt7g36y7g63hvwvoakledwk4b2fr2dl4wzawpnny'
89
88
const options = { cidVersion : 1 , rawLeaves : false }
90
89
91
- const res = await ipfs . add ( testfile , options )
90
+ const res = await all ( ipfs . add ( testfile , options ) )
92
91
93
92
expect ( res ) . to . have . length ( 1 )
94
93
expect ( res [ 0 ] . hash ) . to . equal ( expectedCid )
@@ -98,15 +97,16 @@ describe('.files (the MFS API part)', function () {
98
97
it ( '.add with only-hash=true' , async ( ) => {
99
98
const content = String ( Math . random ( ) + Date . now ( ) )
100
99
101
- const files = await ipfs . add ( Buffer . from ( content ) , { onlyHash : true } )
100
+ const files = await all ( ipfs . add ( Buffer . from ( content ) , { onlyHash : true } ) )
102
101
expect ( files ) . to . have . length ( 1 )
103
102
104
103
// 'ipfs.object.get(<hash>)' should timeout because content wasn't actually added
105
- await expectTimeout ( ipfs . object . get ( files [ 0 ] . hash ) , 4000 )
104
+ return expect ( ipfs . object . get ( files [ 0 ] . hash , { timeout : 2000 } ) )
105
+ . to . be . rejectedWith ( TimeoutError )
106
106
} )
107
107
108
108
it ( '.add with options' , async ( ) => {
109
- const res = await ipfs . add ( testfile , { pin : false } )
109
+ const res = await all ( ipfs . add ( testfile , { pin : false } ) )
110
110
111
111
expect ( res ) . to . have . length ( 1 )
112
112
expect ( res [ 0 ] . hash ) . to . equal ( expectedMultihash )
@@ -116,23 +116,23 @@ describe('.files (the MFS API part)', function () {
116
116
it ( '.add pins by default' , async ( ) => {
117
117
const newContent = Buffer . from ( String ( Math . random ( ) ) )
118
118
119
- const initialPins = await ipfs . pin . ls ( )
119
+ const initialPins = await all ( ipfs . pin . ls ( ) )
120
120
121
- await ipfs . add ( newContent )
121
+ await all ( ipfs . add ( newContent ) )
122
122
123
- const pinsAfterAdd = await ipfs . pin . ls ( )
123
+ const pinsAfterAdd = await all ( ipfs . pin . ls ( ) )
124
124
125
125
expect ( pinsAfterAdd . length ) . to . eql ( initialPins . length + 1 )
126
126
} )
127
127
128
128
it ( '.add with pin=false' , async ( ) => {
129
129
const newContent = Buffer . from ( String ( Math . random ( ) ) )
130
130
131
- const initialPins = await ipfs . pin . ls ( )
131
+ const initialPins = await all ( ipfs . pin . ls ( ) )
132
132
133
- await ipfs . add ( newContent , { pin : false } )
133
+ await all ( ipfs . add ( newContent , { pin : false } ) )
134
134
135
- const pinsAfterAdd = await ipfs . pin . ls ( )
135
+ const pinsAfterAdd = await all ( ipfs . pin . ls ( ) )
136
136
137
137
expect ( pinsAfterAdd . length ) . to . eql ( initialPins . length )
138
138
} )
@@ -146,7 +146,7 @@ describe('.files (the MFS API part)', function () {
146
146
}
147
147
const options = { hashAlg : name , rawLeaves : false }
148
148
149
- const res = await ipfs . add ( [ file ] , options )
149
+ const res = await all ( ipfs . add ( [ file ] , options ) )
150
150
151
151
expect ( res ) . to . have . length ( 1 )
152
152
const cid = new CID ( res [ 0 ] . hash )
@@ -163,7 +163,7 @@ describe('.files (the MFS API part)', function () {
163
163
progress = p
164
164
}
165
165
166
- const res = await ipfs . add ( testfile , { progress : progressHandler } )
166
+ const res = await all ( ipfs . add ( testfile , { progress : progressHandler } ) )
167
167
168
168
expect ( res ) . to . have . length ( 1 )
169
169
expect ( progress ) . to . be . equal ( testfile . byteLength )
@@ -180,7 +180,7 @@ describe('.files (the MFS API part)', function () {
180
180
}
181
181
182
182
// TODO: needs to be using a big file
183
- const res = await ipfs . add ( testfile , { progress : progressHandler } )
183
+ const res = await all ( ipfs . add ( testfile , { progress : progressHandler } ) )
184
184
185
185
expect ( res ) . to . have . length ( 1 )
186
186
expect ( progress ) . to . be . equal ( testfile . byteLength )
@@ -197,15 +197,15 @@ describe('.files (the MFS API part)', function () {
197
197
}
198
198
199
199
// TODO: needs to be using a directory
200
- const res = await ipfs . add ( testfile , { progress : progressHandler } )
200
+ const res = await all ( ipfs . add ( testfile , { progress : progressHandler } ) )
201
201
202
202
expect ( res ) . to . have . length ( 1 )
203
203
expect ( progress ) . to . be . equal ( testfile . byteLength )
204
204
expect ( progressCount ) . to . be . equal ( 1 )
205
205
} )
206
206
207
207
it ( '.add without progress options' , async ( ) => {
208
- const res = await ipfs . add ( testfile )
208
+ const res = await all ( ipfs . add ( testfile ) )
209
209
210
210
expect ( res ) . to . have . length ( 1 )
211
211
} )
@@ -219,44 +219,33 @@ describe('.files (the MFS API part)', function () {
219
219
}
220
220
const options = { hashAlg : name , rawLeaves : false }
221
221
222
- const res = await ipfs . add ( [ file ] , options )
222
+ const res = await all ( ipfs . add ( [ file ] , options ) )
223
223
224
224
expect ( res ) . to . have . length ( 1 )
225
225
const cid = new CID ( res [ 0 ] . hash )
226
226
expect ( mh . decode ( cid . multihash ) . name ) . to . equal ( name )
227
227
} )
228
228
} )
229
229
230
- it ( '.addPullStream with object chunks and pull stream content' , ( done ) => {
230
+ it ( '.add with object chunks and iterable content' , async ( ) => {
231
231
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
232
232
233
- pull (
234
- values ( [ { content : values ( [ Buffer . from ( 'test' ) ] ) } ] ) ,
235
- ipfs . addPullStream ( ) ,
236
- collect ( ( err , res ) => {
237
- expect ( err ) . to . not . exist ( )
238
-
239
- expect ( res ) . to . have . length ( 1 )
240
- expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
241
- done ( )
242
- } )
233
+ const res = await pipe (
234
+ [ { content : [ Buffer . from ( 'test' ) ] } ] ,
235
+ ipfs . add ,
236
+ all
243
237
)
244
- } )
245
-
246
- it ( '.add with pull stream' , async ( ) => {
247
- const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
248
- const res = await ipfs . add ( values ( [ Buffer . from ( 'test' ) ] ) )
249
238
250
239
expect ( res ) . to . have . length ( 1 )
251
240
expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
252
241
} )
253
242
254
- it ( '.add with array of objects with pull stream content ' , async ( ) => {
243
+ it ( '.add with iterable ' , async ( ) => {
255
244
const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
256
- const res = await ipfs . add ( [ { content : values ( [ Buffer . from ( 'test' ) ] ) } ] )
245
+ const res = await all ( ipfs . add ( [ Buffer . from ( 'test' ) ] ) )
257
246
258
247
expect ( res ) . to . have . length ( 1 )
259
- expect ( res [ 0 ] ) . to . eql ( { path : expectedCid , hash : expectedCid , size : 12 } )
248
+ expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
260
249
} )
261
250
262
251
it ( 'files.mkdir' , async ( ) => {
@@ -327,7 +316,7 @@ describe('.files (the MFS API part)', function () {
327
316
await ipfs . files . write ( file , Buffer . from ( 'Hello, world' ) , {
328
317
create : true
329
318
} )
330
- const files = await ipfs . files . ls ( folder )
319
+ const files = await all ( ipfs . files . ls ( folder ) )
331
320
332
321
expect ( files . length ) . to . equal ( 1 )
333
322
} )
@@ -336,7 +325,7 @@ describe('.files (the MFS API part)', function () {
336
325
const folder = `test-folder-${ Math . random ( ) } `
337
326
338
327
await ipfs . files . mkdir ( `/${ folder } ` )
339
- const files = await ipfs . files . ls ( )
328
+ const files = await all ( ipfs . files . ls ( ) )
340
329
341
330
expect ( files . find ( file => file . name === folder ) ) . to . be . ok ( )
342
331
} )
@@ -346,15 +335,15 @@ describe('.files (the MFS API part)', function () {
346
335
create : true
347
336
} )
348
337
349
- const buf = await ipfs . files . read ( '/test-folder/test-file-2.txt' )
338
+ const buf = Buffer . concat ( await all ( ipfs . files . read ( '/test-folder/test-file-2.txt' ) ) )
350
339
351
340
expect ( buf . toString ( ) ) . to . be . equal ( 'hello world' )
352
341
} )
353
342
354
343
it ( 'files.write without options' , async ( ) => {
355
344
await ipfs . files . write ( '/test-folder/test-file-2.txt' , Buffer . from ( 'hello world' ) )
356
345
357
- const buf = await ipfs . files . read ( '/test-folder/test-file-2.txt' )
346
+ const buf = Buffer . concat ( await all ( ipfs . files . read ( '/test-folder/test-file-2.txt' ) ) )
358
347
359
348
expect ( buf . toString ( ) ) . to . be . equal ( 'hello world' )
360
349
} )
@@ -395,7 +384,7 @@ describe('.files (the MFS API part)', function () {
395
384
await ipfs . files . write ( file , testfile , {
396
385
create : true
397
386
} )
398
- const buf = await ipfs . files . read ( file )
387
+ const buf = Buffer . concat ( await all ( ipfs . files . read ( file ) ) )
399
388
400
389
expect ( Buffer . from ( buf ) ) . to . deep . equal ( testfile )
401
390
} )
0 commit comments