2004-11-22
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 2 of 3 )
CabCompressor Class
The CabCompressor class provides an interface to the File Compression interface functionality in CABINET.DLL. It handles a lot of the bookkeeping tasks required for file compression, such as maintaining the FciCurrentCab structure, creating and destroying the FCI context, and supplying GCHandles for managed objects that are passed to FCI functions. It also provides an event interface for the NextCabinet, FilePlaced, and Progress FCI callbacks. Client programs can subscribe to these events to handle the callbacks.
All of the FCI callbacks are implemented as protected virtual functions that inheritors can override in order to change the default functionality. The memory allocation and file I/O callbacks call the common routines that are implemented in the CabIO class.
The public interface to CabCompressor consists primarily of the following methods:
CabCompressorconstructor.- A
Disposemethod. SinceCabCompressorallocates unmanaged resources, it implements theIDisposableinterface so that it can release those resources when the garbage collector cleans up. AddFileadds a file to a cabinet. This corresponds to theFciAddFilefunction.FlushFoldercorresponds toFciFlushFolder.FlushCabinetcorresponds toFciFlushCabinet.
CabCompressor uses a standard .NET event interface. The five events it implements are NextCabinet, FilePlaced, FileAdded, FolderComplete, and CabinetComplete. The event handler delegates use the recommended naming convention (NextCabinetEventHandler, FilePlacedEventHandler, ProgressEventHandler), as do the event arguments. Note that FileAdded, FolderComplete, and CabinetComplete all are of type ProgressEvent and use the ProgressEventArgs event arguments class.
Most of the code in CabCompressor is pretty mundane, concerned with handling the file I/O callbacks and converting the other callback function calls to events and passing them to the client program. Beyond that, there is some slightly complex code to maintain the user data pointer, and a bit of code that allocates and manages the FCI context so that the client program doesn't have to fool with it.
![]() |
|


