Skip to content

Commit bb65217

Browse files
committed
Extract chunk raw content length calculation
1 parent ddc220f commit bb65217

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/org/glavo/nbt/chunk/ChunkRegion.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ static ChunkRegion readRegion(InputContext context) throws IOException {
8080
throw new IOException("Invalid chunk data length: " + chunkRawDataLength);
8181
}
8282

83+
long chunkRawContentLength = chunkRawDataLength - 1L;
84+
8385
int compressType = context.rawReader.readUnsignedByte();
8486
if (compressType > 128) {
85-
if (chunkRawDataLength != 1) {
87+
if (chunkRawContentLength != 0L) {
8688
throw new IOException("Invalid chunk data length: %d (expected 1 for compression type %d)".formatted(chunkRawDataLength, compressType));
8789
}
8890

@@ -91,8 +93,8 @@ static ChunkRegion readRegion(InputContext context) throws IOException {
9193

9294
DataReader reader = switch (compressType) {
9395
case 1 -> throw new IOException("GZip compression is not supported yet.");
94-
case 2 -> new ZlibDataReader(context, chunkRawDataLength - 1L);
95-
case 3 -> new RawDataReader(context, chunkRawDataLength - 1L);
96+
case 2 -> new ZlibDataReader(context, chunkRawContentLength);
97+
case 3 -> new RawDataReader(context, chunkRawContentLength);
9698
case 4 -> throw new IOException("LZ4 compression is not supported yet.");
9799
default -> throw new IOException("Unsupported compression type: " + compressType);
98100
};

0 commit comments

Comments
 (0)