Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 377042b

Browse files
achingbrainAlan Shaw
authored and
Alan Shaw
committed
feat: support adding files via async iterator (#1078)
Adds a method called `ipfs._addAsyncIterator`, prefixed with an underscore to mark it as sort of unofficial (though it's what `ipfs.add` will become once the async iterator migration is complete) and we don't want to implement symmetrical `ipfs.catAsyncIterator` etc methods, or at least not yet.
1 parent 69a56cb commit 377042b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
const SendFilesStream = require('../utils/send-files-stream')
4+
const FileResultStreamConverter = require('../utils/file-result-stream-converter')
5+
6+
module.exports = (send) => {
7+
return async function * (source, options) {
8+
options = options || {}
9+
options.converter = FileResultStreamConverter
10+
11+
const stream = SendFilesStream(send, 'add')(options)
12+
13+
for await (const entry of source) {
14+
stream.write(entry)
15+
}
16+
17+
stream.end()
18+
19+
for await (const entry of stream) {
20+
yield entry
21+
}
22+
}
23+
}

src/files-regular/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = (arg) => {
1212
addFromFs: require('../files-regular/add-from-fs')(send),
1313
addFromURL: require('../files-regular/add-from-url')(send),
1414
addFromStream: require('../files-regular/add')(send),
15+
_addAsyncIterator: require('../files-regular/add-async-iterator')(send),
1516
cat: require('../files-regular/cat')(send),
1617
catReadableStream: require('../files-regular/cat-readable-stream')(send),
1718
catPullStream: require('../files-regular/cat-pull-stream')(send),

src/utils/load-commands.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function requireCommands () {
99
addFromFs: require('../files-regular/add-from-fs'),
1010
addFromURL: require('../files-regular/add-from-url'),
1111
addFromStream: require('../files-regular/add'),
12+
_addAsyncIterator: require('../files-regular/add-async-iterator'),
1213
cat: require('../files-regular/cat'),
1314
catReadableStream: require('../files-regular/cat-readable-stream'),
1415
catPullStream: require('../files-regular/cat-pull-stream'),

0 commit comments

Comments
 (0)