MySQLdb blob and binary data

R

Rune Hansen

I'm storing gzipped data in a MySQL blob field. I can fetch the blob and
"wb" write the data to a file. It becomes a file containg gz data.

I can't take the same data and do anything sensible with it in python -
like say zlib.decompress(data).

How can I convert the binary data from the blob field to the gzipped
string it was stored as (java stores the string, Pickle is not an option)?

regards

/rune
 
D

Denis S. Otkidach

I'm storing gzipped data in a MySQL blob field. I can fetch the blob and
"wb" write the data to a file. It becomes a file containg gz data.

I can't take the same data and do anything sensible with it in python -
like say zlib.decompress(data).

How can I convert the binary data from the blob field to the gzipped
string it was stored as (java stores the string, Pickle is not an option)?

You can pass any file-like object to GzipFile class:

from gzip import GzipFile
from cStringIO import StringIO
GzipFile(fileobj=StringIO(data)).read()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top