On this page
  1. gzip.GzipFile
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

gzip.GzipFile

Prev: gzip.decompress | Up: gzip | Next: gzip.open
Rel: gzip.BadGzipFile, gzip.compress, gzip.decompress, gzip.open
Ref: docs.python.org — gzip.GzipFile
Tags: #public #python3 #stdlib #gzip


Import

import gzip
from gzip import GzipFile

Signature & Overview

gzip.GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)

The GzipFile class simulates most of the methods of a file object with the exception of the truncate() method.

Methods & Attributes

Usage

import gzip
import io

buf = io.BytesIO()
with gzip.GzipFile(fileobj=buf, mode="wb", mtime=0) as gz:
    gz.write(b"deterministic")
buf.seek(0)
with gzip.GzipFile(fileobj=buf, mode="rb") as gz:
    assert gz.read() == b"deterministic"

Gotchas

REPL Inspect

from gzip import GzipFile
help(GzipFile)

Linked from

Related notes