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

Commit

Permalink
feat: add files.ls streaming methods
Browse files Browse the repository at this point in the history
N.b will not actually do any streaming until ipfs/kubo#5611
lands
  • Loading branch information
achingbrain committed Dec 4, 2018
1 parent c191eea commit c203ede
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/files-mfs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = (arg) => {
stat: require('./stat')(send),
rm: require('./rm')(send),
ls: require('./ls')(send),
lsReadableStream: require('./ls-readable-stream')(send),
lsPullStream: require('./ls-pull-stream')(send),
read: require('./read')(send),
readReadableStream: require('./read-readable-stream')(send),
readPullStream: require('./read-pull-stream')(send),
Expand Down
21 changes: 21 additions & 0 deletions src/files-mfs/ls-pull-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const ls = require('./ls')
const defer = require('pull-defer')
const values = require('pull-stream/sources/values')

module.exports = (send) => {
return (args, opts) => {
const deferred = defer.source()

ls(send)(args, opts, (err, entries) => {
if (err) {
return deferred.abort(err)
}

return deferred.resolve(values(entries))
})

return deferred
}
}
10 changes: 10 additions & 0 deletions src/files-mfs/ls-readable-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const lsPullStream = require('./ls-pull-stream')
const toStream = require('pull-stream-to-stream')

module.exports = (send) => {
return (args, opts) => {
return toStream.source(lsPullStream(send)(args, opts))
}
}

0 comments on commit c203ede

Please sign in to comment.