Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: use streaming for cli refs and refs local
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed May 13, 2019
1 parent 29112bb commit 090a2f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/cli/commands/refs-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ module.exports = {
handler ({ getIpfs, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const refs = await ipfs.refs.local()
for (const ref of refs) {
if (ref.err) {
print(ref.err, true, true)
} else {
print(ref.ref)
}
}

return new Promise((resolve, reject) => {
const stream = ipfs.refs.localReadableStream()

stream.on('error', reject)
stream.on('end', resolve)

stream.on('data', (ref) => {
if (ref.err) {
print(ref.err, true, true)
} else {
print(ref.ref)
}
})
})
})())
}
}
23 changes: 15 additions & 8 deletions src/cli/commands/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ module.exports = {

const ipfs = await getIpfs()
const k = [key].concat(keys)
const refs = await ipfs.refs(k, { recursive, format, edges, unique, maxDepth })
for (const ref of refs) {
if (ref.err) {
print(ref.err, true, true)
} else {
print(ref.ref)
}
}

return new Promise((resolve, reject) => {
const stream = ipfs.refsReadableStream(k, { recursive, format, edges, unique, maxDepth })

stream.on('error', reject)
stream.on('end', resolve)

stream.on('data', (ref) => {
if (ref.err) {
print(ref.err, true, true)
} else {
print(ref.ref)
}
})
})
})())
}
}

0 comments on commit 090a2f8

Please sign in to comment.