-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeflateEncoder.php
More file actions
42 lines (32 loc) · 826 Bytes
/
DeflateEncoder.php
File metadata and controls
42 lines (32 loc) · 826 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 gzdeflate;
/**
* deflate encoder.
*/
class DeflateEncoder implements EncoderInterface
{
public const TYPE = 'deflate';
public function encode(string $data): string
{
$data = gzdeflate($data, 9);
if (!$data) {
throw new EncodeFailedException('gzdeflate returned no data.');
}
return $data;
}
public function supports(?string $type): bool
{
return $type === self::TYPE;
}
}