DotNetZip - Calculates the final zip size before calling Save (stream)

When using DotNetZip, is it possible to get the final zip file size before calling Save (stream)? I have a website where users will upload rather large zip files (more than 2 gigabytes), and I would like to be able to transfer the file to the user, rather than buffering the entire file to memory. Something like that...

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

Is it possible?

+2
source share
2 answers

If the flow is uniform, you can spend some time squeezing the "small" part forward, calculating the compression ratio and extrapolating it.

If you want to set the content length header or something like that, you can only do this when you (1) write a temporary file (preferably if there is a risk of connection problems and clients requiring specific pieces) (2) can store entire file in memory (presumably on a 64-bit system with plenty of memory)

Of course, you could spend huge resources and just compress the stream twice, but I hope you agree that it will be stupid.

+3
source

The way to do what you want is to save the file in a temporary file system file, and then transfer the result to the user. This allows you to calculate the size and then transfer the file.

In this case, dotnetzip will not save the file in memory.

+1
source

Source: https://habr.com/ru/post/917006/


All Articles