@@ -15,26 +15,39 @@ import { functionToJson } from '../../serialization/function'
15
15
16
16
export default function ( opts ) {
17
17
const api = {
18
- add : callbackify . variadic (
19
- pre (
20
- ( ...args ) => {
21
- const fileToJsonOpts = { pms : opts }
22
-
23
- // FIXME: implement progress properly
24
- if ( args [ 1 ] && args [ 1 ] . progress ) {
25
- fileToJsonOpts . onProgressIncrement = createOnProgressIncrement ( args [ 1 ] . progress )
26
- delete args [ 1 ] . progress
27
- }
28
-
29
- args [ 0 ] = Array . isArray ( args [ 0 ] )
30
- ? args [ 0 ] . map ( ( file ) => fileToJson ( file , fileToJsonOpts ) )
31
- : fileToJson ( args [ 0 ] , fileToJsonOpts )
32
-
33
- return args
34
- } ,
35
- caller ( 'ipfs.files.add' , opts )
18
+ add : ( ( ) => {
19
+ const add = callbackify . variadic (
20
+ pre (
21
+ ( ...args ) => {
22
+ const fileToJsonOpts = { pms : opts }
23
+
24
+ // FIXME: implement progress properly
25
+ if ( args [ 1 ] && args [ 1 ] . progress ) {
26
+ fileToJsonOpts . onProgressIncrement = createOnProgressIncrement ( args [ 1 ] . progress )
27
+ delete args [ 1 ] . progress
28
+ }
29
+
30
+ args [ 0 ] = Array . isArray ( args [ 0 ] )
31
+ ? args [ 0 ] . map ( ( file ) => fileToJson ( file , fileToJsonOpts ) )
32
+ : fileToJson ( args [ 0 ] , fileToJsonOpts )
33
+
34
+ return args
35
+ } ,
36
+ caller ( 'ipfs.files.add' , opts )
37
+ )
36
38
)
37
- ) ,
39
+
40
+ return ( ...args ) => {
41
+ // Pull streams are just functions and so callbackify.variadic thinks
42
+ // the stream is a callback function! Instead explicitly pass null for
43
+ // the options arg.
44
+ if ( args . length === 1 && isSource ( args [ 0 ] ) ) {
45
+ args = args . concat ( null )
46
+ }
47
+
48
+ return add ( ...args )
49
+ }
50
+ } ) ( ) ,
38
51
// FIXME: implement add readable stream properly
39
52
addReadableStream ( ...args ) {
40
53
const content = [ ]
0 commit comments