from gzip import GzipFile
from collections import deque
dq = deque(maxlen=1)
with GzipFile('firewall.4.gz') as file:
    head = next(file)
dq.extend(file)
tail = dq[0]
Read head / tail of gzip file without reading it into memory