我想通过koa/node.js流ZIP存档 [英] I want to stream a ZIP archive via koa/node.js
本文介绍了我想通过koa/node.js流ZIP存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想流式传输ZIP文件,但是我无法使stream
在Koa
中工作.这是我到目前为止(简体)的内容
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()
})
但是,出现此错误:
Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented
我想念什么?
推荐答案
显然
const stream = new Stream.PassThrough()
绝招:)
这篇关于我想通过koa/node.js流ZIP存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文