Get the entire file in a variable - error

martijn at gamecreators.nl martijn at gamecreators.nl
Thu Apr 14 10:37:11 EDT 2005


H!

I'm using a database and now I want to compress a file and put it into
the database.

So I'm using gzip because php can open the gzip file's.
The only problem is saving the file into the database.

The function below does this:
- gzip the file [oke]
- get all the bytes with tst.getvalue() [error]
I only get the first line.

I have the same problem when I try it with file.open(), .read().

"how to get all the binary data in a variable to put that in a database
LONG field?"

Thank's

def compressFILE(sid,filedata):
    tst = StringIO.StringIO()

    #tmp
    zip = gzip.GzipFile(str(sid)+'.gz','w',5,tst)
    zip.write(filedata)

    #put every byte in a database
    print tst.getvalue()

    zip.close()
    tst.close()

    return




More information about the Python-list mailing list