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.
source share