0

我想流式传输 ZIP 文件,但无法stream使用Koa. 这是我到目前为止所拥有的(简化)

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()
})

但是,我收到此错误:

Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented

我想念什么?

4

1 回答 1

1

显然

const stream = new Stream.PassThrough()

诀窍:)

于 2020-01-29T13:14:27.683 回答