@@ -156,7 +156,26 @@ module.exports = (common) => {
156
156
} )
157
157
} )
158
158
159
- it ( 'a Readable Stream' , ( done ) => {
159
+ it ( 'adds from readable stream' , ( done ) => {
160
+ const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
161
+
162
+ const rs = new Readable ( )
163
+ rs . push ( Buffer . from ( 'some data' ) )
164
+ rs . push ( null )
165
+
166
+ ipfs . files . add ( rs , ( err , filesAdded ) => {
167
+ expect ( err ) . to . not . exist ( )
168
+
169
+ expect ( filesAdded ) . to . be . length ( 1 )
170
+ const file = filesAdded [ 0 ]
171
+ expect ( file . path ) . to . equal ( expectedCid )
172
+ expect ( file . size ) . to . equal ( 17 )
173
+ expect ( file . hash ) . to . equal ( expectedCid )
174
+ done ( )
175
+ } )
176
+ } )
177
+
178
+ it ( 'adds from array of objects with readable stream content' , ( done ) => {
160
179
const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
161
180
162
181
const rs = new Readable ( )
@@ -177,6 +196,37 @@ module.exports = (common) => {
177
196
} )
178
197
} )
179
198
199
+ it ( 'adds from pull stream (callback)' , ( done ) => {
200
+ const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
201
+
202
+ ipfs . files . add ( pull . values ( [ Buffer . from ( 'test' ) ] ) , ( err , res ) => {
203
+ if ( err ) return done ( err )
204
+ expect ( res ) . to . have . length ( 1 )
205
+ expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
206
+ done ( )
207
+ } )
208
+ } )
209
+
210
+ it ( 'adds from pull stream (promise)' , ( ) => {
211
+ const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
212
+
213
+ return ipfs . files . add ( pull . values ( [ Buffer . from ( 'test' ) ] ) )
214
+ . then ( ( res ) => {
215
+ expect ( res ) . to . have . length ( 1 )
216
+ expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
217
+ } )
218
+ } )
219
+
220
+ it ( 'adds from array of objects with pull stream content' , ( ) => {
221
+ const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
222
+
223
+ return ipfs . files . add ( [ { content : pull . values ( [ Buffer . from ( 'test' ) ] ) } ] )
224
+ . then ( ( res ) => {
225
+ expect ( res ) . to . have . length ( 1 )
226
+ expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
227
+ } )
228
+ } )
229
+
180
230
it ( 'add a nested directory as array of tupples' , function ( done ) {
181
231
// TODO: https://github.com/ipfs/js-ipfs-api/issues/339
182
232
if ( ! isNode ) { this . skip ( ) }
@@ -367,6 +417,21 @@ module.exports = (common) => {
367
417
} )
368
418
)
369
419
} )
420
+
421
+ it ( 'adds with object chunks and pull stream content' , ( done ) => {
422
+ const expectedCid = 'QmRf22bZar3WKmojipms22PkXH1MZGmvsqzQtuSvQE3uhm'
423
+
424
+ pull (
425
+ pull . values ( [ { content : pull . values ( [ Buffer . from ( 'test' ) ] ) } ] ) ,
426
+ ipfs . files . addPullStream ( ) ,
427
+ pull . collect ( ( err , res ) => {
428
+ if ( err ) return done ( err )
429
+ expect ( res ) . to . have . length ( 1 )
430
+ expect ( res [ 0 ] ) . to . deep . equal ( { path : expectedCid , hash : expectedCid , size : 12 } )
431
+ done ( )
432
+ } )
433
+ )
434
+ } )
370
435
} )
371
436
372
437
describe ( '.cat' , ( ) => {
0 commit comments