On the presumption that the supplied data is zipped by gzip, this functions writes the date to a temporary file, calls 'gunzip' via a system call on this file and reads in the unziped data. The temporary file and it's unziped associate are then unlinked. Note: Do not unzip files that contain multiple files and/or accross mutiple directories. It won't work and will leave a mess!
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | Gunzip | (hzChain&,hzChain&,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
hzEcode Gunzip (hzChain& orig)hzChain& gzipped,
{
// Category: Codec
//
// On the presumption that the supplied data is zipped by gzip, this functions writes the date to a temporary file, calls 'gunzip' via a system call on this file and reads in
// the unziped data. The temporary file and it's unziped associate are then unlinked.
//
// Arguments: 1) orig The chain to be populated with the unzipped data
// 2) gzipped The chain containing the original (zipped) data
//
// Returns: E_NODATA If there is nothing to do
// E_WRITEFAIL If the original data could not be written out to the temporary file
// E_SYSERROR If the gunzip command could not be found or failed to process the data
// E_READFIAL If the unzipped data could not be read back from the temporary file
// E_OK If the operation was successful
//
// Note: Do not unzip files that contain multiple files and/or accross mutiple directories. It won't work and will leave a mess!
_hzfunc(__func__) ;
z_stream infstream ; // Input
chIter zi ; // Chain iterator
char* tmp ; // Zipped buffer
char* buf ; // Unzipped buffer
uint32_t n ; // Buffer iterator
tmp = new char[gzipped.Size()+1];
buf = new char[20480];
for (n = 0,zi = gzipped ; !zi.eof() ; n++, zi++)
tmp[n] = *zi ;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
// setup "b" as the input and "c" as the compressed output
infstream.avail_in = (uInt) gzipped.Size() ; // size of input
infstream.next_in = (Bytef*)tmp ; // input char array
infstream.avail_out = 20480; // size of output
infstream.next_out = (Bytef*)buf ; // output char array
// the actual DE-compression work.
if (inflateInit2(&infstream, 31)!=Z_OK)
return E_NOINIT ;
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);
for (n = 0; n < infstream.total_out ; n++)
orig.AddByte(buf[n]) ;
delete tmp ;
delete buf ;
return E_OK ;
}