Skip to content

Commit 8cd359b

Browse files
committed
Merge branch 'main' into cli-wrapper
# Conflicts: # src/main/java/dev/zarr/zarrjava/v3/codec/core/ZstdCodec.java
2 parents ab8244d + 4612451 commit 8cd359b

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/main/java/dev/zarr/zarrjava/core/codec/core/ZstdCodec.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.luben.zstd.ZstdCompressCtx;
55
import dev.zarr.zarrjava.ZarrException;
66
import dev.zarr.zarrjava.core.codec.BytesBytesCodec;
7+
import dev.zarr.zarrjava.utils.Utils;
78

89
import java.nio.ByteBuffer;
910

@@ -15,7 +16,7 @@ public abstract class ZstdCodec extends BytesBytesCodec {
1516

1617
@Override
1718
public ByteBuffer decode(ByteBuffer compressedBytes) throws ZarrException {
18-
byte[] compressedArray = compressedBytes.array();
19+
byte[] compressedArray = Utils.toArray(compressedBytes);
1920

2021
long originalSize = Zstd.getFrameContentSize(compressedArray);
2122
if (originalSize == 0) {
@@ -28,7 +29,7 @@ public ByteBuffer decode(ByteBuffer compressedBytes) throws ZarrException {
2829

2930
@Override
3031
public ByteBuffer encode(ByteBuffer chunkBytes) throws ZarrException {
31-
byte[] arr = chunkBytes.array();
32+
byte[] arr = Utils.toArray(chunkBytes);
3233
byte[] compressed;
3334
try (ZstdCompressCtx ctx = new ZstdCompressCtx()) {
3435
ctx.setLevel(getLevel());

src/main/java/dev/zarr/zarrjava/v3/codec/core/ShardingIndexedCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public Array decodePartial(StoreHandle chunkHandle, long[] offset, int[] shape)
249249
if (chunkBytes == null) {
250250
return arrayMetadata.allocateFillValueChunk();
251251
}
252-
return decodeInternal(new ByteBufferDataProvider(chunkHandle.read()), offset, shape, arrayMetadata);
252+
return decodeInternal(new ByteBufferDataProvider(chunkBytes), offset, shape, arrayMetadata);
253253
}
254254
return decodeInternal(new StoreHandleDataProvider(chunkHandle), offset, shape, arrayMetadata);
255255
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrExce
206206
Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.UINT));
207207
}
208208

209+
@Test
210+
public void testShardingWithZstdCodecReadWrite() throws ZarrException, IOException {
211+
int[] testData = new int[16 * 16 * 16];
212+
Arrays.setAll(testData, p -> p);
213+
214+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("testShardingWithZstdCodecReadWrite");
215+
ArrayMetadataBuilder builder = Array.metadataBuilder()
216+
.withShape(16, 16, 16)
217+
.withDataType(DataType.UINT32)
218+
.withChunkShape(8, 8, 8)
219+
.withFillValue(0)
220+
.withCodecs(c -> c.withSharding(new int[]{2, 4, 8}, c1 -> c1.withZstd()));
221+
Array writeArray = Array.create(storeHandle, builder.build());
222+
writeArray.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{16, 16, 16}, testData));
223+
224+
Array readArray = Array.open(storeHandle);
225+
ucar.ma2.Array result = readArray.read();
226+
227+
Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.UINT));
228+
}
229+
209230
@Test
210231
public void testTransposeCodec() throws ZarrException {
211232
ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{2, 3, 3}, new int[]{

0 commit comments

Comments
 (0)