QrZlibB64

object QrZlibB64

Utilities for QR payloads that are Base64-encoded and deflated (zlib/gzip/raw).

Typical QR issuers compress UTF-8 JSON using zlib/DEFLATE or gzip, then encode with Base64 (often Base64URL without padding). This helper:

  • decodeBase64ZlibToString: Base64{URL?} -> inflate{zlib/gzip/raw} -> UTF-8 String

  • encodeToBase64UrlZlib: UTF-8 String -> zlib(deflate) -> Base64URL (no padding)

Safety:

  • Decoding returns null on any failure (bad Base64 / unsupported container / size cap exceeded).

  • A maxOutputBytes guard prevents inflating to unbounded size (zip-bomb protection).

Thread-safety: this object is stateless; methods are thread-safe.

Since

1.0.0

Functions

Link copied to clipboard
@RequiresApi(value = 26)
fun decodeBase64ZlibToString(b64: String, urlSafePreferred: Boolean = true, tolerateMissingPadding: Boolean = true, maxOutputBytes: Int = 2 * 1024 * 1024): String?

Decode a QR payload: Base64 (URL-safe or standard) → inflate (gzip/zlib/raw-deflate) → UTF-8 string.

Link copied to clipboard
@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).