-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGzipEncoder.php
More file actions
42 lines (32 loc) · 814 Bytes
/
GzipEncoder.php
File metadata and controls
42 lines (32 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
/*
* This file is part of the brainbits transcoder package.
*
* (c) brainbits GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Brainbits\Transcoder\Encoder;
use Brainbits\Transcoder\Exception\EncodeFailedException;
use function gzencode;
/**
* gzip encoder.
*/
class GzipEncoder implements EncoderInterface
{
public const TYPE = 'gzip';
public function encode(string $data): string
{
$data = gzencode($data, 9);
if (!$data) {
throw new EncodeFailedException('gzencode returned no data.');
}
return $data;
}
public function supports(?string $type): bool
{
return $type === self::TYPE;
}
}