CompressedData
One of the features the Cryptographic Message Syntax (CMS) provides is to act as a wrapper format for compressed files.
Note that this feature requires the zlib extension be installed (until such time that a shim can be written).
Reading CompressedData CMS
The method for loading a CompressedData CMS is the same as loading any other CMS type:
use phpseclib4\File\CMS;
$cms = CMS::load(file_get_contents('compressed.pem'));
print_r($cms);
$cms, in this case, is a CMS\CompressedData object which, in turn, is basically a thin wrapper around an instance of \phpseclib4\File\ASN1\Constructed. Passing $cms through print_r() or var_dump() triggers the __debugInfo() magic method which, in turn, produces the following output:
contentType
phpseclib4\File\ASN1\Types\OID
content
version
phpseclib4\File\ASN1\Types\Integer
compressionAlgorithm
algorithm
phpseclib4\File\ASN1\Types\OID
encapContentInfo
eContentType
phpseclib4\File\ASN1\Types\OID
eContent
phpseclib4\File\ASN1\Types\OctetString
Extracting file contents
The decompressed content can be extracted by calling $cms->getContent().
Creating CompressedData
use phpseclib4\File\CMS;
$cms = new CMS\CompressedData(file_get_contents('...'));
echo $cms;
Output Format
By default, CMS objects, when cast to a string, are converted to base64-encoded PEMs. To make it so that casting to a string produces a binary encoded DERs one need simply call CMS::enableBinaryOutput(). To go back to PEMs calling CMS::disableBinaryOutput() is sufficient.
You can also convert a CMS object to binary by doing $cms->toString(['binary' => true]).