我想通过koa / node.js传输ZIP存档

问题描述 投票:0回答:1

我想流式传输ZIP文件,但是我无法使streamKoa中工作。这是我到目前为止的内容(简体)

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

我想念什么?

koa node-archiver
1个回答
0
投票

显然

const stream = new Stream.PassThrough()

完成技巧:)

© www.soinside.com 2019 - 2024. All rights reserved.