A stateless, cross-platform, JNI-based wrapper around the c-blosc library.
The packaged JARs contain binaries for Windows, Mac OS (x86_64 and arm64) and Linux.
import dev.zarr.bloscjava.Blosc;
// Generate some random data
int SIZE = 1000000;
byte[] buf = new byte[SIZE];
for (int i = 0; i < SIZE; i++) {
buf[i] = (int)(i % 24);
}
byte[] compressedBuf = Blosc.compress(buf, 1, Blosc.Compressor.ZSTD, 9);
byte[] decompressedBuf = Blosc.decompress(compressedBuf);
assert Arrays.equals(buf, decompressedBuf);byte[] compress(
byte[] src,
int typeSize,
Blosc.Compressor compressor,
int compressorLevel,
Blosc.Shuffle shuffle,
int blockSize,
int numThreads
)src: Byte array to be compressed. Required.typeSize: Number of bytes per primitive value (e.g. 1 for int8, 2 for int16, 4 for int32). Required.compressor: Compression algorithm. Available choices:LZ4,LZ4HC,BLOSCLZ,ZSTD,ZLIB. Default:ZSTDcompressorLevel: Number from 0 to 9 (0 = little compression, 9 = strongest compression). Default: 5.shuffle: Whether to use shuffling. Available choices:NOSHUFFLE,BIT_SHUFFLE,BYTE_SHUFFLE. Default:BIT_SHUFFLEfor typeSize == 1,BYTE_SHUFFLEotherwise.blockSize: Requested size of compressed blocks. Use 0 for automatic block sizes.numThreads: Number of threads to be used internally. Default: 1.
byte[] decompress(byte[] src, int numThreads)src: Byte array to be decompressed. Required.numThreads: Number of threads to be used internally. Default: 1.
Add the dev.zarr.blosc-java dependency to your Maven project:
<dependencies>
<dependency>
<groupId>dev.zarr</groupId>
<artifactId>blosc-java</artifactId>
<version>BLOSC_VERSION</version>
</dependency>
</dependencies>