Filtering in Stream Mode
To use the Filtering stream-based I/O
- Load the
kvfilter
library and obtain the KV_GetFilterInterfaceEx() entry point. Thefilter
sample program contains sample code for all platforms. - Initialize a filter session by calling fpInit() or fpInitWithLicenseData(). This function's return value,
pContext
, is passed as the first argument to all other Filter functions. - Pass the context pointer from fpInit() or fpInitWithLicenseData() and the address of a structure that contains pointers to the File Extraction API functions in the call to
KVGetExtractInterface()
. See KVGetExtractInterface(). - Create an input stream (
KVInputStream
) by calling fpFiletoInputStreamCreate() or by using code similar to the example code in theFilter
sample program. - Open the stream by calling fpOpenStream().
- Declare the input stream in the KVOpenFileArg structure.
- Open the source file by calling fpOpenFile() and passing the
KVOpenFileArg
structure. This call defines the parameters necessary to open a file for extraction. - Determine whether the source file is a container file (that is, whether it contains subfiles) by calling fpGetMainFileInfo().
- If the call to
fpGetMainFileInfo()
determined that the source file is a container file, proceed to step 10; otherwise, proceed to step 13. - Determine whether the subfile is a container file by calling fpGetSubFileInfo().
- Extract the subfile to a stream by calling fpExtractSubFile().
- If the call to
fpGetSubFileInfo()
determined that the subfile is a container file, repeat step 4 through step 11 until all subfiles are extracted; otherwise, proceed to step 13. - Filter the stream by calling fpFilterStream(). Call
fpFilterStream()
repeatedly until the entire output buffer is processed. After each call tofpFilterStream()
, call fpFreeFilterOutput() to free the text buffer returned. - Close the stream by calling fpCloseStream().
- Free the memory allocated for the input stream by calling fpFileToInputStreamFree().
- Close the file by calling fpCloseFile().
- Repeat Step 4 through Step 16 as required for additional source files.
- Terminate the filter session by calling fpShutdown().