unzip

fun ByteArray.unzip(maxBytes: Long = Long.MAX_VALUE): String

Decompresses this ByteArray from GZIP encoding back to a String.

If the byte array is empty, returns an empty string. If the byte array is not GZIP-compressed (no GZIP magic header), returns the raw bytes decoded as UTF-8.

Return

the decompressed string content.

Parameters

maxBytes

the largest decompressed size accepted, which guards against a small input that expands until memory runs out. Defaults to no limit.

Throws

if the decompressed content is larger than maxBytes, or maxBytes is negative.

if the data has a GZIP header but is corrupt or truncated, such as a java.util.zip.ZipException or java.io.EOFException.