Question

I'm attempting to use the 'zlib.inflate' built in stream filter on a file pointer that I'm using with ftp_fget(). The idea is, if the file is gzipped, this will inflate it. Everything works until I attach the stream filter.

    $local = $remote = 'whatever.txt';
    # Create local file to transfer ftp file into
    $localFile = fopen($local, 'w');
    # Attach inflation stream filter with write filter, so we can inflate as we write to the new file
    stream_filter_append($localFile, 'zlib.inflate', STREAM_FILTER_WRITE);
    # Use fget to read remote file into local with optional inflation
    # $this->_connection(); returns csv resource
    $result    = ftp_fget($this->_connection(), $localFile, $remote, FTP_BINARY);

This seems like it should be a pretty straight forward thing, but it's just giving me a blank file. Any ideas?

[Edit] Running PHP 5.2.6 on Debian Lenny. Zlib is installed and shows up under phpinfo()

[Edit 2] It appears this is related to this bug. https://bugs.php.net/bug.php?id=49411 If so, I'll close this out.

[Edit 3] Spun up a Vb instance with PHP 5.4.4 and I'm still having the same issues, so I don't think its a bug.

Was it helpful?

Solution

This was a misunderstanding on my part about how the streams work. They don't support the same headers and trailers that the command line gzip utility would use. (2 bytes at the beginning and a checksum at the end). I'm going to have to attack this from a different angle. I'm going to mark this as solved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top