Back to index

python3.2  3.2.2
Classes | Functions | Variables
gzip Namespace Reference

Classes

class  _PaddedFile
class  GzipFile

Functions

def U32
def LOWU32
def write32u
def read32
def open
def compress
def decompress
def _test

Variables

list __all__ = ["GzipFile", "open", "compress", "decompress"]

Detailed Description

Functions that read and write gzipped files.

The user of the file doesn't have to worry about the compression,
but random access is not allowed.

Function Documentation

def gzip._test ( ) [private]

Definition at line 586 of file gzip.py.

00586 
00587 def _test():
00588     # Act like gzip; with -d, act like gunzip.
00589     # The input file is not deleted, however, nor are any other gzip
00590     # options or features supported.
00591     args = sys.argv[1:]
00592     decompress = args and args[0] == "-d"
00593     if decompress:
00594         args = args[1:]
00595     if not args:
00596         args = ["-"]
00597     for arg in args:
00598         if decompress:
00599             if arg == "-":
00600                 f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
00601                 g = sys.stdout.buffer
00602             else:
00603                 if arg[-3:] != ".gz":
00604                     print("filename doesn't end in .gz:", repr(arg))
00605                     continue
00606                 f = open(arg, "rb")
00607                 g = builtins.open(arg[:-3], "wb")
00608         else:
00609             if arg == "-":
00610                 f = sys.stdin.buffer
00611                 g = GzipFile(filename="", mode="wb", fileobj=sys.stdout.buffer)
00612             else:
00613                 f = builtins.open(arg, "rb")
00614                 g = open(arg + ".gz", "wb")
00615         while True:
00616             chunk = f.read(1024)
00617             if not chunk:
00618                 break
00619             g.write(chunk)
00620         if g is not sys.stdout:
00621             g.close()
00622         if f is not sys.stdin:
00623             f.close()

Here is the call graph for this function:

def gzip.compress (   data,
  compresslevel = 9 
)
Compress data in one shot and return the compressed string.
Optional argument is the compression level, in range of 1-9.

Definition at line 569 of file gzip.py.

00569 
00570 def compress(data, compresslevel=9):
00571     """Compress data in one shot and return the compressed string.
00572     Optional argument is the compression level, in range of 1-9.
00573     """
00574     buf = io.BytesIO()
00575     with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
00576         f.write(data)
00577     return buf.getvalue()

Here is the caller graph for this function:

def gzip.decompress (   data)
Decompress a gzip compressed string in one shot.
Return the decompressed string.

Definition at line 578 of file gzip.py.

00578 
00579 def decompress(data):
00580     """Decompress a gzip compressed string in one shot.
00581     Return the decompressed string.
00582     """
00583     with GzipFile(fileobj=io.BytesIO(data)) as f:
00584         return f.read()
00585 

Here is the caller graph for this function:

def gzip.LOWU32 (   i)
Return the low-order 32 bits, as a non-negative int

Definition at line 27 of file gzip.py.

00027 
00028 def LOWU32(i):
00029     """Return the low-order 32 bits, as a non-negative int"""
00030     return i & 0xFFFFFFFF

def gzip.open (   filename,
  mode = "rb",
  compresslevel = 9 
)
Shorthand for GzipFile(filename, mode, compresslevel).

The filename argument is required; mode defaults to 'rb'
and compresslevel defaults to 9.

Definition at line 39 of file gzip.py.

00039 
00040 def open(filename, mode="rb", compresslevel=9):
00041     """Shorthand for GzipFile(filename, mode, compresslevel).
00042 
00043     The filename argument is required; mode defaults to 'rb'
00044     and compresslevel defaults to 9.
00045 
00046     """
00047     return GzipFile(filename, mode, compresslevel)

Here is the caller graph for this function:

def gzip.read32 (   input)

Definition at line 36 of file gzip.py.

00036 
00037 def read32(input):
00038     return struct.unpack("<I", input.read(4))[0]

Here is the caller graph for this function:

def gzip.U32 (   i)
Return i as an unsigned integer, assuming it fits in 32 bits.
If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.

Definition at line 19 of file gzip.py.

00019 
00020 def U32(i):
00021     """Return i as an unsigned integer, assuming it fits in 32 bits.
00022     If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
00023     """
00024     if i < 0:
00025         i += 1 << 32
00026     return i

def gzip.write32u (   output,
  value 
)

Definition at line 31 of file gzip.py.

00031 
00032 def write32u(output, value):
00033     # The L format writes the bit pattern correctly whether signed
00034     # or unsigned.
00035     output.write(struct.pack("<L", value))

Here is the caller graph for this function:


Variable Documentation

list gzip.__all__ = ["GzipFile", "open", "compress", "decompress"]

Definition at line 13 of file gzip.py.