fun compressEstim(src: ByteArray?, srcOff: Int, srcLen: Int): Int { var srcOff = srcOff if (srcLen < 10) return srcLen var stride: Int = LZ4_64K_LIMIT - 1 val segments = (srcLen + stride - 1) / stride stride = srcLen / segments if (stride >= LZ4_64K_LIMIT - 1 || stride * segments > srcLen || segments < 1 || stride < 1) throw RuntimeException( "?? $srcLen" ) var bytesIn = 0 var bytesOut = 0 var len = srcLen while (len > 0) { if (len > stride) len = stride bytesOut += compress64k(src, srcOff, len) srcOff += len bytesIn += len len = srcLen - bytesIn } val ratio = bytesOut / bytesIn.toDouble() return if (bytesIn == srcLen) bytesOut else (ratio * srcLen + 0.5).toInt() }
Estimates the length of the compressed bytes , as compressed by Lz4 WARNING : if larger than LZ4_64K_LIMIT it cuts it in fragments WARNING : if some part of the input is discarded , this should return the proportional ( so that returnValue/srcLen=compressionRatio )