Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip.Stream 的 addEntry 不能在多个事件循环中使用 #60

Open
weijiafu14 opened this issue Apr 8, 2021 · 1 comment
Open

zip.Stream 的 addEntry 不能在多个事件循环中使用 #60

weijiafu14 opened this issue Apr 8, 2021 · 1 comment

Comments

@weijiafu14
Copy link

weijiafu14 commented Apr 8, 2021

const { zip } = require('compressing');
const fs = require('fs')
const zipStream = new zip.Stream();
zipStream.addEntry('test.html')
setTimeout(() => {
zipStream.addEntry('yarn.lock')
setTimeout(() => {
zipStream.addEntry('package.json')
setTimeout(() => {
zipStream.pipe(fs.createWriteStream('test.zip'));
}, 3000)
}, 3000)
}, 3000)

这段代码最终压缩包里只会有test.html ,原因是每次addEntry后都会调用 finalize ,会使依赖的yazl.zipFile 调用end,调用了end后,会使zipFile处理完最后一个文件后如果没有其他Entry就关闭流,导致压缩结束,所以处理完已添加的文件前如果 addEntry 没调用到,流就会关闭,再调用就不起作用,
所以安全起见,addEntry 要一次性同步调完,或者需要异步用yazl

@IQZoe
Copy link

IQZoe commented Dec 20, 2021

我使用for循环依次addEntry,每次add的是个流,发现压缩后的文件偶发性的会减少

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants