diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 40977d5d2..f65506bbe 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -49,6 +49,9 @@ class ZippedResourcePack implements ResourcePack{ /** @var string */ protected $sha256 = null; + /** @var resource */ + protected $fileResource; + public function __construct(string $zipPath){ $this->path = $zipPath; @@ -74,6 +77,12 @@ class ZippedResourcePack implements ResourcePack{ } $this->manifest = $manifest; + + $this->fileResource = fopen($zipPath, "rb"); + } + + public function __destruct(){ + fclose($this->fileResource); } public function getPackName() : string{ @@ -100,6 +109,10 @@ class ZippedResourcePack implements ResourcePack{ } public function getPackChunk(int $start, int $length) : string{ - return substr(file_get_contents($this->path), $start, $length); + fseek($this->fileResource, $start); + if(feof($this->fileResource)){ + throw new \RuntimeException("Requested a resource pack chunk with invalid start offset"); + } + return fread($this->fileResource, $length); } } \ No newline at end of file