|
| 1 | +# blosc-java |
| 2 | + |
| 3 | +A cross-platform JNI-based wrapper around the [c-blosc](https://github.com/Blosc/c-blosc) library. |
| 4 | + |
| 5 | +The packaged JARs contain binaries for Windows, Mac OS (x86_64 only) and Linux. |
| 6 | + |
| 7 | +## Usage |
| 8 | +```java |
| 9 | +import dev.zarr.bloscjava.Blosc; |
| 10 | + |
| 11 | +// Generate some random data |
| 12 | +int SIZE = 100 * 100 * 100; |
| 13 | +byte[] buf = new byte[SIZE]; |
| 14 | +for (int i = 0; i < SIZE; i++) { |
| 15 | + buf[i] = (int)(i % 24); |
| 16 | +} |
| 17 | + |
| 18 | +byte[] compressedBuf = Blosc.compress(buf, 1, Blosc.Compressor.ZSTD, 9); |
| 19 | +byte[] decompressedBuf = Blosc.decompress(compressedBuf); |
| 20 | + |
| 21 | +assert Arrays.equals(buf, decompressedBuf); |
| 22 | +``` |
| 23 | + |
| 24 | +### API |
| 25 | +```java |
| 26 | +byte[] compress(byte[] src, int typeSize, Compressor compressor, int compressorLevel, Shuffle shuffle, int blockSize, int numThreads) |
| 27 | +``` |
| 28 | + |
| 29 | +- `src`: Byte array to be compressed. Required. |
| 30 | +- `typeSize`: Number of bytes per primitive value (e.g. 1 for int8, 2 for int16, 4 for int32). Required. |
| 31 | +- `compressor`: Compression algorithm. Available choices: `LZ4`, `LZ4HC`, `BLOSCLZ`, `ZSTD`, `SNAPPY`, `ZLIB`. |
| 32 | + Default: `ZSTD` |
| 33 | +- `compressorLevel`: Number from 0 to 9 (0 = little compression, 9 = strongest compression). Default: 5. |
| 34 | +- `shuffle`: Whether to use shuffling. Available choices: `NOSHUFFLE`, `BIT_SHUFFLE`, `BYTE_SHUFFLE`. Default: |
| 35 | + `BIT_SHUFFLE` for typeSize == 1, `BYTE_SHUFFLE` else |
| 36 | +- `blockSize`: Requested size of compressed blocks. Use 0 for automatic block sizes. |
| 37 | +- `numThreads`: Number of threads to be used internally. Default: 1. |
| 38 | + |
| 39 | +```java |
| 40 | +byte[] decompress(byte[] src, int numThreads) |
| 41 | +``` |
| 42 | + |
| 43 | +- `src`: Byte array to be decompressed. Required. |
| 44 | +- `numThreads`: Number of threads to be used internally. Default: 1. |
| 45 | + |
0 commit comments