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

feat: support adding files via async iterator #1078

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/files-regular/add-async-iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const SendFilesStream = require('../utils/send-files-stream')
const FileResultStreamConverter = require('../utils/file-result-stream-converter')

module.exports = (send) => {
return async function * (source, options) {
options = options || {}
options.converter = FileResultStreamConverter

const stream = SendFilesStream(send, 'add')(options)

for await (const entry of source) {
stream.write(entry)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to do some conversion of entry.content?

}

stream.end()

for await (const entry of stream) {
yield entry
}
}
}
1 change: 1 addition & 0 deletions src/files-regular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = (arg) => {
addFromFs: require('../files-regular/add-from-fs')(send),
addFromURL: require('../files-regular/add-from-url')(send),
addFromStream: require('../files-regular/add')(send),
_addAsyncIterator: require('../files-regular/add-async-iterator')(send),
cat: require('../files-regular/cat')(send),
catReadableStream: require('../files-regular/cat-readable-stream')(send),
catPullStream: require('../files-regular/cat-pull-stream')(send),
Expand Down
1 change: 1 addition & 0 deletions src/utils/load-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function requireCommands () {
addFromFs: require('../files-regular/add-from-fs'),
addFromURL: require('../files-regular/add-from-url'),
addFromStream: require('../files-regular/add'),
_addAsyncIterator: require('../files-regular/add-async-iterator'),
cat: require('../files-regular/cat'),
catReadableStream: require('../files-regular/cat-readable-stream'),
catPullStream: require('../files-regular/cat-pull-stream'),
Expand Down