diff --git a/composer.json b/composer.json index 3dde33f0..5483621f 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "ext-brotli": "*", "ext-lz4": "*", "ext-snappy": "*", + "ext-bz2":"*", "php": ">=8.0", "utopia-php/framework": "0.*.*", "utopia-php/system": "0.*.*" diff --git a/src/Storage/Compression/Algorithms/BZIP2.php b/src/Storage/Compression/Algorithms/BZIP2.php new file mode 100644 index 00000000..cd125031 --- /dev/null +++ b/src/Storage/Compression/Algorithms/BZIP2.php @@ -0,0 +1,42 @@ +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); + } + + 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); + + $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); + + $data = $this->object->decompress($data); + $dataSize = mb_strlen($data, '8bit'); + + $this->assertEquals($dataSize, 3038056); + } +} \ No newline at end of file