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

Commit 14d53ce

Browse files
Alan Shawachingbrain
Alan Shaw
authored andcommitted
fix: response for empty dir when ?stream=true
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.
1 parent a6f210e commit 14d53ce

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/http/ls.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,19 @@ const mfsLs = {
3535
cidBase
3636
})
3737

38-
let passThrough
38+
const passThrough = new PassThrough()
3939

4040
readableStream.on('data', (entry) => {
41-
if (!passThrough) {
42-
passThrough = new PassThrough()
43-
resolve(passThrough)
44-
}
45-
41+
resolve(passThrough)
4642
passThrough.write(JSON.stringify(mapEntry(entry)) + '\n')
4743
})
4844

4945
readableStream.once('end', (entry) => {
50-
if (passThrough) {
51-
passThrough.end(entry ? JSON.stringify(mapEntry(entry)) + '\n' : undefined)
52-
}
46+
resolve(passThrough)
47+
passThrough.end(entry ? JSON.stringify(mapEntry(entry)) + '\n' : undefined)
5348
})
5449

55-
readableStream.once('error', (error) => {
56-
reject(error)
57-
})
50+
readableStream.once('error', reject)
5851
})
5952

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

0 commit comments

Comments
 (0)