Home

gzipGzipFile

GzipFile is a class in Python's standard library gzip module that provides a file-like interface for gzip-compressed data. It can be used to read from or write to gzip files, performing compression or decompression on the fly as data passes through the object. The class is designed to integrate with Python’s IO system, making it natural to use with with statements and other file-like operations.

Construction and parameters: GzipFile(filename=None, mode='rb', fileobj=None, mtime=None, compresslevel=None) allows you to specify either a filename or

Interface and usage: As a file-like object, GzipFile implements read(), write(), close(), and flush(), among other

Notes: Seek support in gzip streams is limited and not generally suitable for random access. GzipFile is

an
existing
binary
file-like
object
as
the
underlying
stream.
Typical
modes
are
'rb'
for
reading
and
'wb'
for
writing;
the
underlying
stream
is
treated
as
binary.
When
writing,
you
can
set
compresslevel
(1–9)
to
balance
speed
and
compression
ratio,
and
mtime
controls
the
modification
time
stored
in
the
gzip
header.
If
filename
is
provided,
the
class
opens
that
file;
if
fileobj
is
provided,
it
uses
the
given
stream.
standard
methods.
In
read
mode,
it
decompresses
data
from
the
underlying
stream;
in
write
mode,
it
compresses
uncompressed
data
before
writing.
It
can
be
used
in
a
with
block
and,
for
text
data,
can
be
wrapped
by
an
appropriate
text
wrapper
(for
example,
io.TextIOWrapper)
or
by
using
gzip.open
in
text
mode.
often
used
directly
for
binary
data
or
as
the
underlying
object
for
higher-level
wrappers,
and
it
is
complemented
by
the
gzip.open
function,
a
convenience
interface
that
handles
opening
and
(optionally)
text
wrapping.