3 ms·
> Reading an entire zip file's contents and writing out a brand new zip file could be an extremely slow process. That’s not the reason. Writing to disk and rea
by hinkley 5y ago
> Reading an entire zip file's contents and writing out a brand new zip file could be an extremely slow process.
That’s not the reason. Writing to disk and reading it back is bad, but keeping the whole file in memory is far worse and people seem to forget that routinely.
If you read from the beginning, you can stream the decompression. If you are already taking care not to clobber important files on your filesystem, this isn’t much worse.
The other advantage in the modern era of this format is that you can stream compression of the archive too. Need to send someone a bunch of files? You can start writing the file to the client while still compressing the data. If you’re very brave, you can start sending it while you’re still globbing the file system or pulling database records. This means you aren’t turning CPU time on the source into latency at the receiving end.