Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit ca48731

Browse files
committed
fix: allows pull stream to be passed as only arg to add
1 parent f7cb12f commit ca48731

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/client/files/add.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,39 @@ import { functionToJson } from '../../serialization/function'
1515

1616
export default function (opts) {
1717
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+
)
3638
)
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+
})(),
3851
// FIXME: implement add readable stream properly
3952
addReadableStream (...args) {
4053
const content = []

0 commit comments

Comments
 (0)