common gzip stream stuff

(this is not tested, but it's a lot more testable at least, so maybe
I'll do that later)