If you have PHP running on your server, and you want to decompress a zlib-compressed string in Javascript, an alternative to using the zlib.js
library would be to use the Fetch API
to re-contact the server and then simply gzuncompress()
using PHP.
Example:
const decompressString = async (compressedString) => {
const decompressionScriptFilepath = '/decompress-string.php';
const compressedStringToSend = { method: 'POST', body: compressedString };
const response = await fetch(decompressionScriptFilepath, compressedStringToSend);
return await response.text();
}
PHP Script at /decompress-string.php
<?php
$Compressed_String = file_get_contents('php://input');
$decompressedString = gzuncompress($Compressed_String);
echo $decompressedString;
?>
Then you simply need to invoke the javascript function:
decompressString('eNoLycgsVgCiRIWS1OISPYWQUf4of5Q/yh/lj/JH+aP8wc0HAERY4KM=');