Contents

compression_stream_process(_:_:)

Performs compression or decompression using an initialized compression stream structure.

Declaration

func compression_stream_process(_ stream: UnsafeMutablePointer<compression_stream>, _ flags: Int32) -> compression_status

Parameters

Return Value

A value of type compression_status, interpreted as follows:

Discussion

Each time compression_stream_process(_:_:) is called successfully, the function consumes data from the source buffer and writes data into the destination buffer, until it reaches the end of one of the buffers and returns either COMPRESSION_STATUS_OK or COMPRESSION_STATUS_END.

After a successful call, the function updates the buffer parameters in the stream object: the function increments src_ptr (and decrements src_size) by the number of input bytes consumed. Likewise, the function incremets dst_ptr (and decrements dst_size) by the number of output bytes produced. The sum (src_ptr + src_size) remains unchanged, and so does (dst_ptr + dst_size). At this point, either src_size or dst_size will be 0, indicating that the source buffer is empty or the destination buffer is full.

If the source buffer is empty, you can refill it with more data and adjust the parameters, or point to a different buffer for the next call. If you don’t provide any more input data, set flags to COMPRESSION_STREAM_FINALIZE and call again.

If the destination buffer is full and the return value is not COMPRESSION_STATUS_END, there may still be input available for processing. To let this happen, you might grow the buffer, move the pointer back to reuse the buffer, or point to a new destination buffer, and then call again.

See Also

Multiple-step compression