The Callback Function


When you create a compression or decompression engine, you must supply a function pointer. This function is called whenever either engine has data to output. The function then takes the data and do whatever the application wants with the data. For example, the callback function can deposit the data in a buffer, and once the engine is deleted, the buffer can be written out to a file.

The callback function has two parameters passed to it, and is defined as:

typedef void (* CompFunc)(void *userData, uint32 word);
The userData field is normally NULL, unless you supply the COMP_TAG_USERDATA tag when creating the engine. Whatever value is associated with the tag gets passed directly to the callback function. The purpose of the userData field is to pass things like a file pointer to the callback function. You would pass the file pointer as the data value associated with the COMP_TAG_USERDATA tag. The engines then pass the value to the callback function whenever it is called.

The word parameter to the callback is the word of data being generated by the engine. You must do something useful with this word. For example, you could copy it into a memory buffer, or write it to a file.