DotNetZip - Calculate final zip size before calling Save(stream)

青春壹個敷衍的年華 提交于 2019-12-10 22:23:53

问题


When using DotNetZip, is it possible to get what the final zip file size will be before calling Save(stream)? I have a website where users will be downloading fairly large zip files (over 2 gigs), and I would like to be able to stream the file to the user rather then buffering the entire file into memory. Some thing like this...

response.BufferOutput = false;
response.AddHeader("Content-Length", ????);

Is this possible?


回答1:


If the stream is homogenous, you could waste some time by compressing a 'small' portion ahead, calculating the compression ratio and extrapolating from that.

If you are meaning to set a content-length header or something like that, it can only be done when you (1) write a temporary file (advisable if there is any risk of connection trouble and clients requesting specific chunks anyway) (2) can keep the entire file in memory (presumably on ly on 64bit system with copious memory)

Of course, you could waste enormous resources and just compress the stream twice, but I hope you agree that would be silly.




回答2:


The way to do what you want is to save the file to a temporary filesystem file, then stream the result to the user. This lets you compute the size then transmit the file.

In this case dotnetzip will not save the file into memory.



来源:https://stackoverflow.com/questions/5402497/dotnetzip-calculate-final-zip-size-before-calling-savestream

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