mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 18:29:46 +00:00
Use a resource for reading resource packs from disk
This commit is contained in:
parent
b7b73aab23
commit
cc0b4d888e
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user