I can check the integrity of a gzip file with gzip -t file.gz
and zcat file.gz > /dev/null
as per previous answers.
Sometimes I have jobs dying before a compression of a large file finishes. I will get an error about unexpected end of file, if I check the file from beginning to end. But is it possible to only test, that there is no unexpected end of the compressed file, so I don't have to read through the entire file?
EDIT 2018 in accordance with answer from Mark Adler below (Python 3.2+ solution):
import os
import string
import gzip
with gzip.open('test.gz', 'wt') as f:
f.write(string.ascii_lowercase)
with open('test.gz', 'rb') as f:
f.seek(-4 , os.SEEK_END)
length = int.from_bytes(f.read(), byteorder='little')
assert length == 26
print('Thanks Mark Adler!')
print('The English alphabet has {length} letters.'.format(length=length))