Skip to content

Commit

Permalink
add CustomCompressionReader
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Jan 31, 2024
1 parent bff2270 commit ad97560
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Chunk/AnvilChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Aternos\Thanos\Chunk;

use Aternos\Thanos\Reader\CustomCompressionReader;
use Aternos\Thanos\Reader\LZ4BlockReader;
use Aternos\Thanos\Reader\RawReader;
use Aternos\Thanos\Reader\ReaderInterface;
Expand Down Expand Up @@ -142,6 +143,13 @@ public function __construct($file, int $offset, array $regionPosition, int $regi
$dataLength
);
break;
case 127:
$this->reader = new CustomCompressionReader(
$this->file,
$this->dataOffset,
$dataLength
);
break;
default:
throw new Exception("Unknown chunk compression type.");
}
Expand Down
47 changes: 47 additions & 0 deletions src/Reader/CustomCompressionReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Aternos\Thanos\Reader;

use Exception;

class CustomCompressionReader extends BufferedReader
{
protected string $compressionType;

/**
* @inheritDoc
* @throws Exception
*/
public function __construct($resource, int $offset, int $length)
{
parent::__construct($resource, $offset, $length);

$this->compressionType = $this->readCompressionType();
throw new Exception("Unsupported custom compression type: " . $this->compressionType);
}

/**
* @return string
* @throws Exception
*/
protected function readCompressionType(): string
{
$result = "";
while ($char = $this->readRaw(1)) {
if (ord($char) !== 0) {
break;
}
$result .= $char;
}
return $result;
}

/**
* @inheritDoc
* @throws Exception
*/
protected function getRawChunk(int $length): string
{
return $this->readRaw($length);
}
}

0 comments on commit ad97560

Please sign in to comment.