Problem
In my service, users can download very large (5+ gigabyte) data packages as zip files. The current implementation locates all of the files within the data package, creates a new zip file, populates the zip file with copies of the files, and then streams it to the user.
This isn't scaling well with the larger data packages and I'm trying to find a way to increase the efficiency of this process. I have a proposed solution below, but I don't have experience with serving content and would like professional insight on the best way to go about this.
Attempted Solution
I think the best way is to not copy the actual bytes into the zip file. Instead, create a zipfile of symlinks, and then copy the bytes while streaming the content. I've had issues with actually copying the bytes into the zip during transfer, and I don't know if this is possible anymore.
End Solution
I implemented the accepted answer from Alexey Ragozin below into SpeedBagIt, a library for efficiently streaming zip files conforming to the BagIt specification.