encodeToBase64UrlZlib

@RequiresApi(value = 26)
fun encodeToBase64UrlZlib(input: String, level: Int = Deflater.BEST_COMPRESSION, onlyIfSmaller: Boolean = true): String

Compress a UTF-8 string with zlib (DEFLATE + zlib header/Adler32) and encode as Base64URL (no padding).

If onlyIfSmaller is true and compression does not reduce size, this returns the original input string (mirrors common mobile behavior where short payloads aren’t worth compressing).

Example

val b64 = QrZlibB64.encodeToBase64UrlZlib(json)
// b64 is Base64URL with no '=' padding

Return

Base64URL (no padding) string of zlib-compressed bytes, or the original input if not smaller and onlyIfSmaller = true.

Parameters

input

UTF-8 text to compress.

level

zlib compression level (see Deflater), default BEST_COMPRESSION.

onlyIfSmaller

If true, return input unchanged when compression is not beneficial.