Created
August 22, 2018 10:12
-
-
Save jayaregalinada/19b9c38e0eec1e0a11c504fe85474286 to your computer and use it in GitHub Desktop.
File content compress using gzcompress and gzuncompress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Make sure you have a file.txt within this directory. | |
/** @var string File path location */ | |
$fileLocation = __DIR__ . DIRECTORY_SEPARATOR . "file.txt"; | |
/** @var Streams The stream of the file. */ | |
$fileStream = fopen($fileLocation, 'r'); | |
/** @var Streams|string The content of the file. */ | |
$read = fread($fileStream, filesize($fileLocation)); | |
// http://php.net/manual/en/function.gzcompress.php | |
$compress = gzcompress($read); | |
// Print the compress content. | |
echo join([ | |
'<pre>', | |
$compress, | |
'</pre><pre>', | |
'String length ', | |
strlen($compress), | |
'</pre>' | |
]); | |
// http://php.net/manual/en/function.gzuncompress.php | |
$uncompress = gzuncompress($compress); | |
echo '<hr />'; | |
// Print the uncompress content. | |
echo join([ | |
'<pre>', | |
$uncompress, | |
'</pre><pre>', | |
'String length ', | |
strlen($uncompress), | |
'</pre>' | |
]); | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment