Search code examples
c#dotnetzip

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


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?


Solution

  • 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.