herbrandson
herbrandson

Reputation: 2417

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?

Upvotes: 2

Views: 1818

Answers (2)

Cheeso
Cheeso

Reputation: 192627

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.

Upvotes: 1

sehe
sehe

Reputation: 393694

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.

Upvotes: 3

Related Questions