Function

uni_compress

Compress text.

Since v1.0
unistat uni_compress(
const void *text, unisize text_len, uniattr text_attr, uint8_t *buffer, size_t *buffer_length)

Parameters 🔗

text in

Text to compress.

text_len in

Length of text in code units or -1 if text is null terminated.

text_attr in

Attributes of text.

buffer out

Compressed blob of bytes.

buffer_length inout

Capacity of buffer on input; number of bytes in the compressed text on output.

Return Value 🔗

UNI_OK

On success.

UNI_NO_SPACE

If buffer is not large enough.

UNI_BAD_OPERATION

If text or buffer_length is NULL.

UNI_BAD_ENCODING

If text is not well-formed (checks are omitted if text_attr has UNI_TRUST).

UNI_FEATURE_DISABLED

If Unicorn was configured without support for the compression algorithm.

Discussion 🔗

Compress text using Binary Ordered Compression for Unicode (BOCU-1) and writes the results to buffer. Text is compressed based on its code points, i.e. UTF-8, 16, and 32 will compress to the same byte sequence.

The capacity of buffer is specified by buffer_length. The implementation always writes to buffer_length the total number of bytes in the fully compressed text. If the capacity of buffer is insufficient, then UNI_NO_SPACE is returned otherwise it returns UNI_OK. If buffer is NULL, then buffer_length must be zero.