创建ZIP响应而不实际创建机器中的所有文件
我程序中的主要端点操纵了很多数据,并最终创建了zip文件,其中包含带有几个子目录和一些文件(在子目录之间拆分)的父目录。将邮政编码发送回客户端后,将删除在此过程中创建的所有内容,因为为了启动zip文件,创建了唯一的工作。 主要目标是将zip文件作为对用户的响应发送。
在性能方面,是否可以在没有实际创建文件夹的情况下执行此逻辑。所有端点调用的子文件夹和文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以做得更好。您可以在记忆中完全执行此操作,而不是操纵硬盘上的物理数据。
正如评论部分中提到的@olivier所述,您需要输出流。
例如,您有一个控制器,该控制器将
.txt
文件返回为zip:在给定的
outputstream
通过内存数据响应中生成zip文件:当然: ,此
GenerateZip
函数只是演示拉链操作并将其写入输出流的一个示例。您需要在
GenerateZip
中实现逻辑。您可以阅读有关邮政操作的更多信息,例如一个文件zipping中的多个文件,等等。 “ nofollow noreferrer”>在这里。
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
.txt
file as a zip:To generate a zip file on the given
OutPutStream
in response by in-memory data:Of course, this
generateZip
function 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.
@Sororh Shemshadi感谢您的帮助。
设法解决了这个问题。
对于将来需要的任何人 -
控制器:
逻辑:
zipmemorymodel:
@allargsconstructor
公共类zipmemorymodel {
}调用:
带虚拟数据的
@Soroush Shemshadi Thank you for your help.
Managed to solve this thing.
For anyone who will need this in the future -
Controller:
Logic:
ZipMemoryModel:
@AllArgsConstructor
public class ZipMemoryModel {
}
Invocation with dummy data: