File tree 6 files changed +41
-23
lines changed
6 files changed +41
-23
lines changed Original file line number Diff line number Diff line change 17
17
"require" : {
18
18
"pocketmine/binaryutils" : " ^0.2.1" ,
19
19
"php-64bit" : " *" ,
20
- "ext-zlib" : " *"
20
+ "ext-zlib" : " *" ,
21
+ "ext-json" : " *"
21
22
}
22
23
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Aternos \Nbt \IO \Reader ;
4
4
5
+ use Exception ;
6
+
5
7
class GZipCompressedStringReader extends StringReader
6
8
{
9
+ /**
10
+ * @throws Exception
11
+ */
7
12
public function __construct (string $ data , int $ format )
8
13
{
9
- parent ::__construct (gzdecode ($ data ), $ format );
14
+ if (($ uncompressed = @gzdecode ($ data )) === false ) {
15
+ throw new Exception ("Invalid GZip data " );
16
+ }
17
+ parent ::__construct ($ uncompressed , $ format );
10
18
}
11
19
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Aternos \Nbt \IO \Reader ;
4
4
5
+ use Exception ;
6
+
5
7
class ZLibCompressedStringReader extends StringReader
6
8
{
9
+ /**
10
+ * @throws Exception
11
+ */
7
12
public function __construct (string $ data , int $ format )
8
13
{
9
- parent ::__construct (zlib_decode ($ data ), $ format );
14
+ if (($ uncompressed = @zlib_decode ($ data )) === false ) {
15
+ throw new Exception ("Invalid ZLib data " );
16
+ }
17
+ parent ::__construct ($ uncompressed , $ format );
10
18
}
11
19
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Aternos \Nbt \IO \Writer ;
4
4
5
+ use Exception ;
6
+
5
7
class GZipCompressedStringWriter extends StringWriter
6
8
{
9
+ /**
10
+ * @throws Exception
11
+ */
7
12
public function getStringData (): string
8
13
{
9
- return gzencode (parent ::getStringData ());
14
+ if (($ compressed = @gzencode (parent ::getStringData ())) === false ) {
15
+ throw new Exception ("Failed to apply GZip compression " );
16
+ }
17
+ return $ compressed ;
10
18
}
11
19
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Aternos \Nbt \IO \Writer ;
4
4
5
+ use Exception ;
6
+
5
7
class ZLibCompressedStringWriter extends StringWriter
6
8
{
9
+ /**
10
+ * @throws Exception
11
+ */
7
12
public function getStringData (): string
8
13
{
9
- return zlib_encode (parent ::getStringData (), ZLIB_ENCODING_DEFLATE );
14
+ if (($ compressed = @zlib_encode (parent ::getStringData (), ZLIB_ENCODING_DEFLATE )) === false ) {
15
+ throw new Exception ("Failed to apply ZLib compression " );
16
+ }
17
+ return $ compressed ;
10
18
}
11
19
}
Original file line number Diff line number Diff line change 7
7
use Aternos \Nbt \NbtFormat ;
8
8
use Aternos \Nbt \Serializer \NbtSerializer ;
9
9
use Exception ;
10
+ use JsonSerializable ;
10
11
11
- abstract class Tag implements \ JsonSerializable
12
+ abstract class Tag implements JsonSerializable
12
13
{
13
14
public const TYPE = -1 ;
14
15
@@ -143,22 +144,6 @@ public function write(Writer $writer): Tag
143
144
return $ this ;
144
145
}
145
146
146
- /**
147
- * @param string $type
148
- * @param string $value
149
- * @return mixed
150
- * @throws Exception
151
- * @deprecated
152
- */
153
- protected function unpack (string $ type , string $ value )
154
- {
155
- $ unpacked = @unpack ($ type , $ value );
156
- if ($ unpacked === false ) {
157
- throw new Exception ("Failed to unpack " . $ type . " from " . bin2hex ($ value ));
158
- }
159
- return $ unpacked [1 ];
160
- }
161
-
162
147
/**
163
148
* @param string $str
164
149
* @return string
@@ -195,7 +180,7 @@ abstract protected function getValueString(): string;
195
180
*/
196
181
public static function getTagClass (int $ type ): ?string
197
182
{
198
- return static ::TAGS [$ type ] ?: null ;
183
+ return static ::TAGS [$ type ] ?? null ;
199
184
}
200
185
201
186
/**
You can’t perform that action at this time.
0 commit comments