The main endpoint in my program manipulates lot's of data and eventually creates Zip file, which contains parent directory with a few sub directories and a few files(splitted between the sub directories). After sending the zip back to the client, all the content which was created during the process will be deleted, as their only job was to be created in order to initiate the zip file. The main goal is to send the zip file as a response to the user.
In terms of performance, is there a way to execute this logic without actually creating the folder & all it's sub folders and files for each invocation of the endpoint?
Yes, you can do it better. Instead of manipulating physical data on your hard disk, you can do it totally on memory.
As @Olivier mentioned in the comment section, you need an output stream.
For example, you have a controller which returns a
.txtfile as a zip:To generate a zip file on the given
OutPutStreamin response by in-memory data:Of course, this
generateZipfunction is just an example of demonstrating the zipping operation and writing it on the output stream.You need to implement your logic in
generateZip.You can read more about zip operations such as multiple files in one file zipping, etc. here.