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

Commit

Permalink
fix: response for empty dir when ?stream=true
Browse files Browse the repository at this point in the history
The new `ipfs-http-client` sets the `stream` option by default. When enabled, the MFS HTTP API [fails this test](https://github.com/ipfs/interface-js-ipfs-core/blob/c766dbff654fd259f7094070ee71858091898750/src/files-mfs/ls.js#L106-L112) because it waits for the first item before sending a response. Since no items are yielded and the stream ends it waits forever.
  • Loading branch information
Alan Shaw authored and achingbrain committed Nov 22, 2019
1 parent a6f210e commit 14d53ce
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/http/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,19 @@ const mfsLs = {
cidBase
})

let passThrough
const passThrough = new PassThrough()

readableStream.on('data', (entry) => {
if (!passThrough) {
passThrough = new PassThrough()
resolve(passThrough)
}

resolve(passThrough)
passThrough.write(JSON.stringify(mapEntry(entry)) + '\n')
})

readableStream.once('end', (entry) => {
if (passThrough) {
passThrough.end(entry ? JSON.stringify(mapEntry(entry)) + '\n' : undefined)
}
resolve(passThrough)
passThrough.end(entry ? JSON.stringify(mapEntry(entry)) + '\n' : undefined)
})

readableStream.once('error', (error) => {
reject(error)
})
readableStream.once('error', reject)
})

return h.response(responseStream).header('X-Stream-Output', '1')
Expand Down

0 comments on commit 14d53ce

Please sign in to comment.