Return Type | Function name | Arguments |
---|---|---|
hzEcode | Gzip | (hzChain&,const hzChain&,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
hzEcode Gzip (hzChain& gzipped, const hzChain& orig) { _hzfunc(__func__) ; chIter zi ; z_stream defstream; char* tmp ; char* buf ; int32_t err ; gzipped.Clear() ; if (!orig.Size()) return E_NODATA ; // Deflate original data defstream.zalloc = Z_NULL; defstream.zfree = Z_NULL; defstream.opaque = Z_NULL; // setup tmp as the input and buf as the compressed output tmp = new char[orig.Size()+1]; buf = new char[orig.Size()] ; zi = orig ; zi.Write(tmp, orig.Size()) ; tmp[orig.Size()] = 0; defstream.avail_in = (uInt) orig.Size() ; defstream.next_in = (Bytef*) tmp; defstream.avail_out = (uInt) orig.Size() ; defstream.next_out = (Bytef*) buf; err = deflateInit2(&defstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31,8,Z_DEFAULT_STRATEGY); if (err != Z_OK) return hzerr(E_NOINIT, "Could not run deflate process") ; // the actual compression work. deflate(&defstream, Z_FINISH); deflateEnd(&defstream); gzipped.Append(buf, defstream.total_out) ; delete tmp ; delete buf ; if (!gzipped.Size()) return hzerr(E_NODATA, "Input %d bytes but no output", orig.Size()) ; return E_OK ; }