Compressed File I/O
The compressed file class provides compression and decompression services for data written to and from a file. The class supports two modes: a compression mode that supports a subset of access methods and a regular mode that supports ordinary CFile method calls.
NOTE >> Because the compression file class compresses its data as a whole, you cannot see the middle of a compressed data block to perform partial decompression. However, by switching back and forth between compressed mode and normal mode, you can write compressed data to a file in a different location. In addition, you can place a jump table at the beginning of the file to store seek locations of the different compressed blocks.
SECCompressFile
SECCompressFile is a CFile derivative that provides compression and decompression services for data written to and read from a file. SECCompressFile has no logic to determine where compressed blocks begin and end. You need to treat an entire file as a single compressed block or be able to seek to the beginning block of compressed data and read in the correct number of compressed bytes.
Figure 133 – Objective Toolkit’s Compressed File Class Hierarchy
SECCompressFile provides a SetCompressedMode() method to treat the file as a compressed file type or as a normal CFile type. The user can treat the entire file as a single compressed block of data or jump to known locations and decompress a smaller portion.
Using SECCompressFile
The following sections describe how you can write and read compressed data.
To write to a file in compressed file format:
1. Create an instance of SECCompressFile.
2. Call the WriteHuge() method to write out data in a compressed file format.
3. Close SECCompressFile.
To read a compressed file:
1. Create an instance of SECCompressFile.
2. Call the ReadHuge() method to read data from the compressed file format.
3. Close SECCompressFile.
To compress CDocument data:
Override the CDocument::GetFile() method as follows:
 
CFile* CMyDoc::GetFile(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException*
pError)
{
 
SECCompressFile* pFile =
new SECCompressFile(lpszFileName, nOpenFlags);
return pFile;
}
SECCompressFile Sample
See the Objective Toolkit CFiles sample in the Samples\Toolkit\MFC\Utility\CFiles directory for an example of how to use SECCompressFile. This sample does not ship with the product. For information on how to obtain this sample, see “Location of Sample Code” in the Getting Started part.