Completed
Push — master ( a40da0...54c502 )
by Freek
02:50
created

Gzip::compress()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Backup\Tasks\Backup;
4
5
class Gzip
6
{
7
    public static function compress(string $inputFile): string
8
    {
9
        if (! file_exists($inputFile)) {
10
            throw new \InvalidArgumentException("Inputfile `{$inputFile}` does not exist.");
11
        }
12
13
        $inputHandle = fopen($inputFile, 'rb');
14
15
        $outputFile = $inputFile . '.gz';
16
        $outputHandle = gzopen($outputFile, 'w9');
17
18
        while (!feof($inputHandle)) {
19
            gzwrite($outputHandle, fread($inputHandle, 1024 * 512));
20
        }
21
22
        fclose($inputHandle);
23
        gzclose($outputHandle);
24
25
        return $outputFile;
26
    }
27
}
28