From 991e67ac295a6cb2b716aa6150d1dac9ca10d2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Besson?= Date: Fri, 27 Mar 2026 08:52:34 +0000 Subject: [PATCH] CodecBuilder: use level for Gzip and Zstd codecs While the blosc codec uses clevel internally, the gzip and zstd codec use level. This updates the signature of the CodecBuilder API to be consistent with GzipConfiguration and ZstdConfiguration. --- .../dev/zarr/zarrjava/v3/codec/CodecBuilder.java | 12 ++++++------ src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java | 10 +++++----- src/test/java/dev/zarr/zarrjava/ZarrV3Test.java | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java b/src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java index 8bddb8a..d4eb697 100644 --- a/src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java +++ b/src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java @@ -83,9 +83,9 @@ public CodecBuilder withBytes() { return withBytes(Endian.nativeOrder()); } - public CodecBuilder withGzip(int clevel) { + public CodecBuilder withGzip(int level) { try { - codecs.add(new GzipCodec(new GzipCodec.Configuration(clevel))); + codecs.add(new GzipCodec(new GzipCodec.Configuration(level))); } catch (ZarrException e) { throw new RuntimeException(e); } @@ -96,9 +96,9 @@ public CodecBuilder withGzip() { return withGzip(5); } - public CodecBuilder withZstd(int clevel, boolean checksum) { + public CodecBuilder withZstd(int level, boolean checksum) { try { - codecs.add(new ZstdCodec(new ZstdCodec.Configuration(clevel, checksum))); + codecs.add(new ZstdCodec(new ZstdCodec.Configuration(level, checksum))); } catch (ZarrException e) { throw new RuntimeException(e); } @@ -109,8 +109,8 @@ public CodecBuilder withZstd() { return withZstd(5, true); } - public CodecBuilder withZstd(int clevel) { - return withZstd(clevel, true); + public CodecBuilder withZstd(int level) { + return withZstd(level, true); } public CodecBuilder withSharding(int[] chunkShape) { diff --git a/src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java b/src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java index c5e797d..5c22b5f 100644 --- a/src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java +++ b/src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java @@ -161,9 +161,9 @@ public void testWriteV3(String codec, String codecParam, DataType dataType) thro builder = builder.withCodecs(c -> c.withGzip(Integer.parseInt(codecParam))); break; case "zstd": - int clevel_zstd = Integer.parseInt(codecParam.split("_")[0]); + int level_zstd = Integer.parseInt(codecParam.split("_")[0]); boolean checksum = Boolean.parseBoolean(codecParam.split("_")[1]); - builder = builder.withCodecs(c -> c.withZstd(clevel_zstd, checksum)); + builder = builder.withCodecs(c -> c.withZstd(level_zstd, checksum)); break; case "bytes": builder = builder.withCodecs(c -> c.withBytes(codecParam)); @@ -270,13 +270,13 @@ public void testWriteV2(String compressor, String compressorParam, dev.zarr.zarr @CsvSource({"0,true", "0,false", "5, true", "10, false"}) @ParameterizedTest - public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException, InterruptedException { + public void testZstdLibrary(int level, boolean checksumFlag) throws IOException, InterruptedException { //compress using ZstdCompressCtx int number = 123456; byte[] src = ByteBuffer.allocate(4).putInt(number).array(); byte[] compressed; try (ZstdCompressCtx ctx = new ZstdCompressCtx()) { - ctx.setLevel(clevel); + ctx.setLevel(level); ctx.setChecksum(checksumFlag); compressed = ctx.compress(src); } @@ -286,7 +286,7 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException Assertions.assertEquals(number, ByteBuffer.wrap(decompressed).getInt()); //write compressed to file - String compressedDataPath = TESTOUTPUT.resolve("compressed" + clevel + checksumFlag + ".bin").toString(); + String compressedDataPath = TESTOUTPUT.resolve("compressed" + level + checksumFlag + ".bin").toString(); try (FileOutputStream fos = new FileOutputStream(compressedDataPath)) { fos.write(compressed); } diff --git a/src/test/java/dev/zarr/zarrjava/ZarrV3Test.java b/src/test/java/dev/zarr/zarrjava/ZarrV3Test.java index 68f7390..614a2b9 100644 --- a/src/test/java/dev/zarr/zarrjava/ZarrV3Test.java +++ b/src/test/java/dev/zarr/zarrjava/ZarrV3Test.java @@ -204,17 +204,17 @@ public void testCheckShardingBounds(int[] shardSize, boolean nested) { @ParameterizedTest @CsvSource({"0,true", "0,false", "5, true", "5, false"}) - public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrException, IOException { + public void testZstdCodecReadWrite(int level, boolean checksum) throws ZarrException, IOException { int[] testData = new int[16 * 16 * 16]; Arrays.setAll(testData, p -> p); - StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testZstdCodecReadWrite", "checksum_" + checksum, "clevel_" + clevel); + StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testZstdCodecReadWrite", "checksum_" + checksum, "level_" + level); ArrayMetadataBuilder builder = Array.metadataBuilder() .withShape(16, 16, 16) .withDataType(DataType.UINT32) .withChunkShape(2, 4, 8) .withFillValue(0) - .withCodecs(c -> c.withZstd(clevel, checksum)); + .withCodecs(c -> c.withZstd(level, checksum)); Array writeArray = Array.create(storeHandle, builder.build()); writeArray.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{16, 16, 16}, testData));