zlib/gzip + anydbm or ...

Jeremy Yallop jeremy at jdyallop.freeserve.co.uk
Wed Jun 19 06:34:34 EDT 2002


* James T. Dennis
| Is there an obvious and simple way to use the existing standard
| libraries to support transparently compressed dbm files?
| 
| (Any combination of zlib/gzip etc with any of the dbm files would
| be considered).

I've done something similar to this before using dbhash/gdbm and zlib.

The code was something like:

import dbhash, zlib, tempfile

   if file_exists(filename):
       dbfile = open(filename)
       tmpfilename = tempfile.mktemp()
       temporary_file = open(tmpfilename, 'w')
       
       temporary_file.write(zlib.decompress(dbfile.read()))
       temporary_file.flush()
       dbfile.close()

       db = dbhash.open(tmpfilename, mode)

with code to recompress the file when the database is closed.

It worked fairly well, but I was only using it for fairly small files
(20 megabytes or less).

If you'd like the full code (around 180 lines) contact me by email.

Jeremy.




More information about the Python-list mailing list