columnarDecompressWithNative function

Uint8List? columnarDecompressWithNative(
  1. Uint8List compressed,
  2. int algorithm
)

algorithm is 1 = zstd, 2 = lz4 (see Rust CompressionType).

Implementation

Uint8List? columnarDecompressWithNative(
  Uint8List compressed,
  int algorithm,
) {
  _bindOnce();
  final d = _decomp;
  final freeFn = _decompFree;
  if (d == null || freeFn == null) {
    return null;
  }
  if (compressed.lengthInBytes > 0x7fffffff) {
    return null;
  }
  final inP = malloc<ffi.Uint8>(compressed.length);
  inP.asTypedList(compressed.length).setAll(0, compressed);
  final outP = malloc<ffi.Pointer<ffi.Uint8>>();
  outP.value = ffi.Pointer<ffi.Uint8>.fromAddress(0);
  final oLen = malloc<ffi.Uint32>();
  final oCap = malloc<ffi.Uint32>();
  try {
    final st = d(algorithm, inP, compressed.length, outP, oLen, oCap);
    if (st != 0) {
      return null;
    }
    final ptr = outP.value;
    if (ptr.address == 0) {
      return null;
    }
    final len = oLen.value;
    final out = Uint8List.fromList(ptr.asTypedList(len));
    freeFn(ptr, len, oCap.value);
    return out;
  } finally {
    malloc.free(inP);
    malloc.free(outP);
    malloc.free(oLen);
    malloc.free(oCap);
  }
}