-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat 3996 bzip2 compression #89
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Utopia\Storage\Compression\Algorithms; | ||
|
||
use Utopia\Storage\Compression\Compression; | ||
|
||
class BZIP2 extends Compression | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'bzip2'; | ||
} | ||
|
||
/** | ||
* Compress. | ||
* | ||
* @see https://www.php.net/manual/en/function.bzcompress.php | ||
* | ||
* @param string $data | ||
* @return string | ||
*/ | ||
public function compress(string $data): string | ||
{ | ||
return \bzcompress($data); | ||
} | ||
|
||
/** | ||
* Decompress. | ||
* | ||
* @see https://www.php.net/manual/en/function.bzdecompress.php | ||
* | ||
* @param string $data | ||
* @return string | ||
*/ | ||
public function decompress(string $data):string | ||
{ | ||
return \bzdecompress($data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Utopia\Tests\Storage\Compression\Algorithms; | ||
use Utopia\Storage\Compression\Algorithms\BZIP2; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BZIP2Test extends TestCase | ||
{ | ||
/** @var BZIP2 */ | ||
protected BZIP2 $object; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->object = new BZIP2(); | ||
} | ||
|
||
public function testName() | ||
{ | ||
$this->assertEquals($this->object->getName(), 'bzip2'); | ||
} | ||
|
||
public function testCompressDecompressWithText() | ||
{ | ||
$demo = 'This is a demo string'; | ||
$demoSize = mb_strlen($demo, '8bit'); | ||
|
||
$data = $this->object->compress($demo); | ||
$dataSize = mb_strlen($data, '8bit'); | ||
|
||
$this->assertEquals($demoSize, 21); | ||
$this->assertEquals($dataSize, 58); | ||
|
||
$this->assertEquals($this->object->decompress($data), $demo); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the |
||
public function testCompressDecompressWithJPGImage() | ||
{ | ||
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); | ||
$demoSize = mb_strlen($demo, '8bit'); | ||
|
||
$data = $this->object->compress($demo); | ||
$dataSize = mb_strlen($data, '8bit'); | ||
|
||
$this->assertEquals($demoSize, 599639); | ||
$this->assertEquals($dataSize, 598565); | ||
|
||
$this->assertGreaterThan($dataSize, $demoSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is necessary |
||
|
||
$data = $this->object->decompress($data); | ||
$dataSize = mb_strlen($data, '8bit'); | ||
|
||
$this->assertEquals($dataSize, 599639); | ||
} | ||
|
||
public function testCompressDecompressWithPNGImage() | ||
{ | ||
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); | ||
$demoSize = mb_strlen($demo, '8bit'); | ||
|
||
$data = $this->object->compress($demo); | ||
$dataSize = mb_strlen($data, '8bit'); | ||
|
||
$this->assertEquals($demoSize, 3038056); | ||
$this->assertEquals($dataSize, 2999345); | ||
|
||
$this->assertGreaterThan($dataSize, $demoSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this |
||
|
||
$data = $this->object->decompress($data); | ||
$dataSize = mb_strlen($data, '8bit'); | ||
|
||
$this->assertEquals($dataSize, 3038056); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this file
BZIP2Test.php
?