https://github.com/jcreedcmu/psql-gunzip-test is the result of messing around last night and this morning. Turns out it's not actually that useful for the particular problem I was dealing with at work, but it was an educational wild goose chase at least.