How does something like System.IO.Compression.GZipStream have anychance of working? Doesn’t something like GZip need to look at the contents of an entire unzipped file before it can start writing the zip file?
Does GZipStream buffer everything before it writes anything? If so, what is the point of implementing the stream?
Most (if not all) common compression algorithms are stream algorithms, i.e. they take streamable input and produce output. Usually they do processing in blocks of certain size, sometimes called windows size, but still they do processing sequentially. They don’t need to know anything about the complete stream (neither it’s full size nor contents).
Some packers do scan the input files in order to determine, which compression algorithm would be more applicable (when multiple algorithms are supported). For example, they might choose text compression algorithms if they find the input to be text or contain large text blocks. But this is not how algorithm itself works, it’s just how packer works.