Skip to content

Commit 991e67a

Browse files
committed
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.
1 parent 8dfef02 commit 991e67a

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public CodecBuilder withBytes() {
8383
return withBytes(Endian.nativeOrder());
8484
}
8585

86-
public CodecBuilder withGzip(int clevel) {
86+
public CodecBuilder withGzip(int level) {
8787
try {
88-
codecs.add(new GzipCodec(new GzipCodec.Configuration(clevel)));
88+
codecs.add(new GzipCodec(new GzipCodec.Configuration(level)));
8989
} catch (ZarrException e) {
9090
throw new RuntimeException(e);
9191
}
@@ -96,9 +96,9 @@ public CodecBuilder withGzip() {
9696
return withGzip(5);
9797
}
9898

99-
public CodecBuilder withZstd(int clevel, boolean checksum) {
99+
public CodecBuilder withZstd(int level, boolean checksum) {
100100
try {
101-
codecs.add(new ZstdCodec(new ZstdCodec.Configuration(clevel, checksum)));
101+
codecs.add(new ZstdCodec(new ZstdCodec.Configuration(level, checksum)));
102102
} catch (ZarrException e) {
103103
throw new RuntimeException(e);
104104
}
@@ -109,8 +109,8 @@ public CodecBuilder withZstd() {
109109
return withZstd(5, true);
110110
}
111111

112-
public CodecBuilder withZstd(int clevel) {
113-
return withZstd(clevel, true);
112+
public CodecBuilder withZstd(int level) {
113+
return withZstd(level, true);
114114
}
115115

116116
public CodecBuilder withSharding(int[] chunkShape) {

src/test/java/dev/zarr/zarrjava/ZarrPythonTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ public void testWriteV3(String codec, String codecParam, DataType dataType) thro
161161
builder = builder.withCodecs(c -> c.withGzip(Integer.parseInt(codecParam)));
162162
break;
163163
case "zstd":
164-
int clevel_zstd = Integer.parseInt(codecParam.split("_")[0]);
164+
int level_zstd = Integer.parseInt(codecParam.split("_")[0]);
165165
boolean checksum = Boolean.parseBoolean(codecParam.split("_")[1]);
166-
builder = builder.withCodecs(c -> c.withZstd(clevel_zstd, checksum));
166+
builder = builder.withCodecs(c -> c.withZstd(level_zstd, checksum));
167167
break;
168168
case "bytes":
169169
builder = builder.withCodecs(c -> c.withBytes(codecParam));
@@ -270,13 +270,13 @@ public void testWriteV2(String compressor, String compressorParam, dev.zarr.zarr
270270

271271
@CsvSource({"0,true", "0,false", "5, true", "10, false"})
272272
@ParameterizedTest
273-
public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException, InterruptedException {
273+
public void testZstdLibrary(int level, boolean checksumFlag) throws IOException, InterruptedException {
274274
//compress using ZstdCompressCtx
275275
int number = 123456;
276276
byte[] src = ByteBuffer.allocate(4).putInt(number).array();
277277
byte[] compressed;
278278
try (ZstdCompressCtx ctx = new ZstdCompressCtx()) {
279-
ctx.setLevel(clevel);
279+
ctx.setLevel(level);
280280
ctx.setChecksum(checksumFlag);
281281
compressed = ctx.compress(src);
282282
}
@@ -286,7 +286,7 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException
286286
Assertions.assertEquals(number, ByteBuffer.wrap(decompressed).getInt());
287287

288288
//write compressed to file
289-
String compressedDataPath = TESTOUTPUT.resolve("compressed" + clevel + checksumFlag + ".bin").toString();
289+
String compressedDataPath = TESTOUTPUT.resolve("compressed" + level + checksumFlag + ".bin").toString();
290290
try (FileOutputStream fos = new FileOutputStream(compressedDataPath)) {
291291
fos.write(compressed);
292292
}

src/test/java/dev/zarr/zarrjava/ZarrV3Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ public void testCheckShardingBounds(int[] shardSize, boolean nested) {
204204

205205
@ParameterizedTest
206206
@CsvSource({"0,true", "0,false", "5, true", "5, false"})
207-
public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrException, IOException {
207+
public void testZstdCodecReadWrite(int level, boolean checksum) throws ZarrException, IOException {
208208
int[] testData = new int[16 * 16 * 16];
209209
Arrays.setAll(testData, p -> p);
210210

211-
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testZstdCodecReadWrite", "checksum_" + checksum, "clevel_" + clevel);
211+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testZstdCodecReadWrite", "checksum_" + checksum, "level_" + level);
212212
ArrayMetadataBuilder builder = Array.metadataBuilder()
213213
.withShape(16, 16, 16)
214214
.withDataType(DataType.UINT32)
215215
.withChunkShape(2, 4, 8)
216216
.withFillValue(0)
217-
.withCodecs(c -> c.withZstd(clevel, checksum));
217+
.withCodecs(c -> c.withZstd(level, checksum));
218218
Array writeArray = Array.create(storeHandle, builder.build());
219219
writeArray.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{16, 16, 16}, testData));
220220

0 commit comments

Comments
 (0)