mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
is this better compression?
This commit is contained in:
parent
37386004d2
commit
05b9b2820c
2 changed files with 36 additions and 1 deletions
35
lib/tools/Gzip.class.php
Normal file
35
lib/tools/Gzip.class.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Gzip
|
||||||
|
{
|
||||||
|
public static function compressFile($source, $level = 1)
|
||||||
|
{
|
||||||
|
$compressedPath = $source . '.gz';
|
||||||
|
$mode = 'wb' . $level;
|
||||||
|
|
||||||
|
$fpOut = gzopen($compressedPath, $mode);
|
||||||
|
if (!$fpOut)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fpIn = fopen($source, 'rb');
|
||||||
|
$error = false;
|
||||||
|
if ($fpIn)
|
||||||
|
{
|
||||||
|
while (!feof($fpIn))
|
||||||
|
{
|
||||||
|
gzwrite($fpOut, fread($fpIn, 1024 * 512));
|
||||||
|
}
|
||||||
|
fclose($fpIn);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
gzclose($fpOut);
|
||||||
|
|
||||||
|
return $error ? false : $compressedPath;
|
||||||
|
}
|
||||||
|
}
|
|
@ -149,7 +149,7 @@ class View
|
||||||
{
|
{
|
||||||
foreach(glob("$dir/*.$ext") as $file)
|
foreach(glob("$dir/*.$ext") as $file)
|
||||||
{
|
{
|
||||||
file_put_contents($file.'.gz', gzencode(file_get_contents($file)));
|
Gzip::compressFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue