libmspack
|
A compressor for .CHM (Microsoft HTMLHelp) files. More...
#include <mspack.h>
Data Fields | |
int(* | generate )(struct mschm_compressor *self, struct mschmc_file file_list[], const char *output_file) |
Generates a CHM help file. More... | |
int(* | use_temporary_file )(struct mschm_compressor *self, int use_temp_file, const char *temp_file) |
Specifies whether a temporary file is used during CHM generation. More... | |
int(* | set_param )(struct mschm_compressor *self, int param, int value) |
Sets a CHM compression engine parameter. More... | |
int(* | last_error )(struct mschm_compressor *self) |
Returns the error code set by the most recently called method. More... | |
A compressor for .CHM (Microsoft HTMLHelp) files.
All fields are READ ONLY.
int(* mschm_compressor::generate) (struct mschm_compressor *self, struct mschmc_file file_list[], const char *output_file) |
Generates a CHM help file.
The help file will contain up to two sections, an Uncompressed section and potentially an MSCompressed (LZX compressed) section.
While the contents listing of a CHM file is always in lexical order, the file list passed in will be taken as the correct order for files within the sections. It is in your interest to place similar files together for better compression.
There are two modes of generation, to use a temporary file or not to use one. See use_temporary_file() for the behaviour of generate() in these two different modes.
self | a self-referential pointer to the mschm_compressor instance being called |
file_list | an array of mschmc_file structures, terminated with an entry whose mschmc_file::section field is MSCHMC_ENDLIST. The order of the list is preserved within each section. The length of any mschmc_file::chm_filename string cannot exceed roughly 4096 bytes. Each source file must be able to supply as many bytes as given in the mschmc_file::length field. |
output_file | the file to write the generated CHM helpfile to. This is passed directly to mspack_system::open() |
int(* mschm_compressor::last_error) (struct mschm_compressor *self) |
Returns the error code set by the most recently called method.
self | a self-referential pointer to the mschm_compressor instance being called |
int(* mschm_compressor::set_param) (struct mschm_compressor *self, int param, int value) |
Sets a CHM compression engine parameter.
The following parameters are defined:
self | a self-referential pointer to the mschm_compressor instance being called |
param | the parameter to set |
value | the value to set the parameter to |
int(* mschm_compressor::use_temporary_file) (struct mschm_compressor *self, int use_temp_file, const char *temp_file) |
Specifies whether a temporary file is used during CHM generation.
The CHM file format includes data about the compressed section (such as its overall size) that is stored in the output CHM file prior to the compressed section itself. This unavoidably requires that the compressed section has to be generated, before these details can be set. There are several ways this can be handled. Firstly, the compressed section could be generated entirely in memory before writing any of the output CHM file. This approach is not used in libmspack, as the compressed section can exceed the addressable memory space on most architectures.
libmspack has two options, either to write these unknowable sections with blank data, generate the compressed section, then re-open the output file for update once the compressed section has been completed, or to write the compressed section to a temporary file, then write the entire output file at once, performing a simple file-to-file copy for the compressed section.
The simple solution of buffering the entire compressed section in memory can still be used, if desired. As the temporary file's filename is passed directly to mspack_system::open(), it is possible for a custom mspack_system implementation to hold this file in memory, without writing to a disk.
If a temporary file is set, generate() performs the following sequence of events: the temporary file is opened for writing, the compression algorithm writes to the temporary file, the temporary file is closed. Then the output file is opened for writing and the temporary file is re-opened for reading. The output file is written and the temporary file is read from. Both files are then closed. The temporary file itself is not deleted. If that is desired, the temporary file should be deleted after the completion of generate(), if it exists.
If a temporary file is set not to be used, generate() performs the following sequence of events: the output file is opened for writing, then it is written and closed. The output file is then re-opened for update, the appropriate sections are seek()ed to and re-written, then the output file is closed.
self | a self-referential pointer to the mschm_compressor instance being called |
use_temp_file | non-zero if the temporary file should be used, zero if the temporary file should not be used. |
temp_file | a file to temporarily write compressed data to, before opening it for reading and copying the contents to the output file. This is passed directly to mspack_system::open(). |