问题
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.
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.
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