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().
- Pass the context pointer that was initialized using fpInit() and the address of a structure that contains pointers to the File Extraction API functions in the call to fpGetExtractInterface().
- 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.NOTE: With fpOpenFile(), you can only open one container at a time (per context pointer).
- 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().
TIP: Alternatively you can open the subfile as a random access input stream by calling fpOpenSubFile(). If you want to pass the stream back into KeyView, you must create a new context using fpInit() (and use the new context on the same thread).
- 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.NOTE: After calling fpFilterStream(), you must finish filtering the stream before calling any other interface function. You can do this by calling fpFilterStream() repeatedly, or by calling fpCloseStream() at any time.
- 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().