pocketmine\nbt\NBT::writeCompressed PHP Метод

writeCompressed() публичный Метод

public writeCompressed ( $compression = ZLIB_ENCODING_GZIP, $level = 7 )
    public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7)
    {
        if (($write = $this->write()) !== false) {
            return zlib_encode($write, $compression, $level);
        }
        return false;
    }

Usage Example

 public function saveMacro($name, Macro $macro)
 {
     $tag = new tag\Compound();
     $tag["author"] = new tag\String("author", $macro->getAuthor());
     $tag["description"] = new tag\String("description", $macro->getDescription());
     $tag["ops"] = new tag\Enum("ops");
     foreach ($macro->getOperations() as $i => $log) {
         $tag["ops"][$i] = $log->toTag();
     }
     $nbt = new NBT();
     $nbt->setData($tag);
     $file = $this->getFile($name);
     $stream = fopen($file, "wb");
     if (!is_resource($stream)) {
         throw new \RuntimeException("Unable to open stream. Maybe the macro name is not a valid filename?");
     }
     $compression = $this->getMain()->getConfig()->getAll()["data providers"]["macro"]["mcr"]["compression"];
     if ($compression === 0) {
         $data = $nbt->write();
     } else {
         $data = $nbt->writeCompressed($compression);
     }
     fwrite($stream, chr($compression) . $data);
     fclose($stream);
 }
All Usage Examples Of pocketmine\nbt\NBT::writeCompressed