Adding files into existing zipped archive with NodeJs zip-stream or archiver module

删除回忆录丶 提交于 2021-02-19 05:07:07

问题


I have this scenario:

I have a zip file for users to download but for each download, I want to include a 'readme' file with user specific content ( e.g. with user's name and download time ). I used archiver (zip-stream) module to zip and stream zipped content to the browser. The goal is to minimise CPU usage (i.e. zipping) and storage ( i.e. creating copy of the same zip). Here are some of the possible ways to achieve this with cons.

  1. Upon every download, make a copy of the original zip, and then add the dynamically generated readme file to the copy before streaming to the browser. This will create many duplicated copies of the original zip file if many users are downloading at the same time. This is not acceptable as the zip file can be as big as 2Gb.

  2. Upon every download, create a new zip for streaming that include the original zip file and the readme file. This saves on CPU and storage as the new zip is created on the fly. but that means user has to unzip twice after downloading and it is not acceptable.

I wonder if I can store a "unfinalise" zip file and append the readme file to it before finalising it and streaming it to the browser.

来源:https://stackoverflow.com/questions/22902901/adding-files-into-existing-zipped-archive-with-nodejs-zip-stream-or-archiver-mod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!