i want to stream a ZIP file, but I can not get the stream
to work in Koa
. Here is what I have so far (simplified)
import Stream from 'stream'
import archiver from 'archiver'
...
router.get('/zip', async ctx => {
ctx.set('Content-Type', 'application/zip')
const content = 'Hey there!'
const archive = archiver('zip', {
zlib: { level: 9 },
})
const stream = new Stream.Duplex()
ctx.body = stream
archive.pipe(stream)
archive.append(content, { name: `hello.txt` })
archive.finalize()
})
However, I get this error:
Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented
What do i miss?
Apparently
const stream = new Stream.PassThrough()
does the trick :)