Skip to content Skip to sidebar Skip to footer

Decompress Sharpziplib String In Php Or Js?

I am on a linux server connecting to a webservice via PHP/Soap. The problem is that a method is zipping the response via SharpZipLib. So all I get in return is a garbled string.

Solution 1:

Chances are, it's using gzip. You should look into PHP Zlib and the gzdecode or gzdeflate methods. You'll probably need to look at the Content type header or another response header.

Something you can try is also setting an Accept header in the web service request that tells the service you don't know how to deal with compression. If it's a proper service, it will honor the request.

EDIT Looking at the .pdf, they're sending the data as a zip archive - so you need to find a PHP lib that deals with in memory zip archives. The C# code they use to decode it is pretty straightforward - they just read all the entries in the archive and expand them. You can try storing it as an in memory buffer using a PHP wrapper along with PHP Zip.

Did you try setting an Accept Header that asks for no compression?

Solution 2:

You can unzip your string using such function:

functiondecode($data)
{
    $filename = tempnam('/tmp', 'tempfile');
    file_put_contents($filename, base64_decode($data));

    $zip = zip_open($filename);
    $entry = zip_read($zip);

    $decoded = zip_entry_read($entry);

    zip_entry_close($entry);
    zip_close($zip);

    return$decoded;
}

Post a Comment for "Decompress Sharpziplib String In Php Or Js?"