Uncompress a gzip file from CURL, on php

40,440

Solution 1

Use gzdecode:

<?php
    $c = file_get_contents("http://torcache.com/" .
        "torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent");
    echo gzdecode($c);

gives

d8:announce42:http://tracker.openbittorrent.com/announce13:announce-listll42
...

Solution 2

Just tell cURL to decode the response automatically whenever it's gzipped

curl_setopt($ch,CURLOPT_ENCODING, '');

Solution 3

libcurl offers a feature that makes it decompress the contents automatically (if built with zlib).

See the CURLOPT_ACCEPT_ENCODING option: https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html

Solution 4

With a zlib Stream Wrapper:

file_get_contents("compress.zlib://http://torcache.com/" .
    "torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent");

Solution 5

Have you tried setting the header stating that you accept gzip encoding as follows?:

curl_setopt($rCurl, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip,deflate'));
Share:
40,440
PartySoft
Author by

PartySoft

Updated on December 10, 2020

Comments

  • PartySoft
    PartySoft over 3 years

    Does anyone know how to uncompress the contents of a gzip file that i got with curl?

    for example: http://torcache.com/torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent

    responded

    HTTP/1.1 200 OK
    Server: nginx
    Date: Wed, 09 Jun 2010 01:11:26 GMT
    Content-Type: application/x-bittorrent
    Content-Length: 52712
    Last-Modified: Tue, 08 Jun 2010 15:09:58 GMT
    Connection: keep-alive
    Expires: Fri, 09 Jul 2010 01:11:26 GMT
    Cache-Control: max-age=2592000
    Content-Encoding: gzip
    Accept-Ranges: bytes
    

    then the compressed gzip,

    i tried gzdecode but doesn't work , gzeflate as well doesn't they simply don't get any response, and the contents of the files are no more than 2k