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 content size accepted, in bytes before UTF-8 decoding. For gzip input it is the decompressed size, which guards against a small input that expands until memory runs out; input without the gzip header is held to it as it is. Defaults to no limit.

Throws

if the content, decompressed or not, 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. Both Java forms declare it.