elif isize != (self._stream_size & 0xffffffff):
raise OSError("Incorrect length of data produced")
# Gzip files can be padded with zeroes and still have archives.
# Consume all zero bytes and set the file position to the first
# non-zero byte. See http://www.gzip.org/#faq8
def compress(data, compresslevel=9):
"""Compress data in one shot and return the compressed string.
Optional argument is the compression level, in range of 0-9.
with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
"""Decompress a gzip compressed string in one shot.
Return the decompressed string.
with GzipFile(fileobj=io.BytesIO(data)) as f:
# Act like gzip; with -d, act like gunzip.
# The input file is not deleted, however, nor are any other gzip
# options or features supported.
decompress = args and args[0] == "-d"
f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
print("filename doesn't end in .gz:", repr(arg))
g = builtins.open(arg[:-3], "wb")
g = GzipFile(filename="", mode="wb", fileobj=sys.stdout.buffer)
f = builtins.open(arg, "rb")
g = open(arg + ".gz", "wb")
if g is not sys.stdout.buffer:
if f is not sys.stdin.buffer:
if __name__ == '__main__':