From: akuchlin at cnri.reston.va.us (Andrew M. Kuchling)
Date: Mon, 26 Apr 1999 15:36:49 -0400 (EDT)
Subject: Using the compression module
In-Reply-To: <7g2ddf$dra$1@birch.prod.itd.earthlink.net>
References: <7g2ddf$dra$1@birch.prod.itd.earthlink.net>
Message-ID: <14116.48932.822574.914523@amarok.cnri.reston.va.us>
Content-Length: 1470
X-UID: 716                                                  

Benjamin Derstine writes:
>From the gzip documentation:
>open (fileobj[, filename[, mode[, compresslevel]]])
>     Returns a new GzipFile object on top of fileobj, which can be a regular
>file, a StringIO object, or any object which simulates a file.

	Are you sure that's what the documentation says?  The current
documentation has filename, mode, compresslevel, fileobj, which
matches the code.  Check the current documentation on
www.python.org/doc/lib/ .

>f=open('/Audit.dbf','r')
>test=gzip.GzipFile('Auditc','r','9',f)

	The first line opens Audit.dbf for reading.  However, if you
want to make a compressed version of it, the second line is wrong;
it's trying to make a compressed file object from the uncompressed
/Audit.dbf.  Instead, you need to open a compressed file for writing:

f=open('/Audit.dbf','r')
test=gzip.GzipFile('Auditc', 'w')

test.write() will then write data to the compressed file, so you need
a loop to copy between the two files:

while 1:
    chunk = f.read(4096)    # Work in chunks of 4K
    if chunk == "": break   # End-of-file?  Break out of the loop
    test.write( chunk )
f.close()
test.close()

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
I had known him for years in a casual way, but I had never seen very deeply
into him. He seemed to me to have more conscience than is good for any man. A
powerful conscience and no sense of humour -- a dangerous combination.
    -- Robertson Davies, _The Rebel Angels_


	




