curl-and-python

compressing FTP data through a callback

From: jd list <jdlists_at_gmail.com>
Date: Mon, 27 Mar 2006 13:57:38 +0100

I was trying to compress the data sent with pycurl, using FTP via a
read callback. I was using a simple class based callback

class FileReader:
    def __init__(self, fp,compress=False):
        self.fp = fp
        self.zip = compress

    def read_callback(self, size):
        if self.zip is False:
            return self.fp.read(size)
        else:
            return zlib.compress(self.fp.read(size))

which was called by (another object)

self.c.setopt(self.c.READFUNCTION, FileReader(open(flNm, 'rb')).read_callback)

When i set compress to True, the file gets stuck in a some sort of
loop, and the output file grows eternally on the FTP Server. settting
to False and simple returning the contents, works as desired.

I'm sure i'm missing something simple here, and was hoping someone
could point me in the right direction.

Thanks
Jeff

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2006-03-27