Index: gzip.rst =================================================================== --- gzip.rst (revision 76139) +++ gzip.rst (working copy) @@ -79,7 +79,18 @@ The *filename* argument is required; *mode* defaults to ``'rb'`` and *compresslevel* defaults to ``9``. +.. function:: compress(string[, level]) + Compresses the data in *string*, returning a string containing compressed data. + *level* is an integer from ``1`` to ``9`` controlling the level of compression; + ``1`` is the fastest and produces the least compression, ``9`` is slowest and + produces the best. The default value is ``9``. + +.. function:: decompress(string) + + Decompresses the data in *string*, returning a string containing the + uncompressed data. + .. _gzip-usage-examples: Examples of usage @@ -109,7 +120,19 @@ f_out.close() f_in.close() +Example of how to GZIP compress a string:: + import gzip + s_in = "Lots of content here" + s_out = gzip.compress(s_in) + # Write the string to a file + open('/home/joe/file.txt.gz','wb').write(s_out) + # Read it back again + f = gzip.open('/home/joe/file.txt.gz', 'rb') + file_content = f.read() + f.close() + + .. seealso:: Module :mod:`zlib`