Return TypeFunction nameArguments
hzEcodeGzip(hzChain&,const hzChain&,)

Declared in file: hzCodec.h
Defined in file : hzCodec.cpp

Function Logic:

0:START 1:hzChain::Clear hzChain::Size 2:!orig.Size() 3:Return E_NODATA 4:defstream defstream defstream tmp buf zi hzChain::Size hzChain::Iter::Write hzChain::Size tmp hzChain::Size defstream defstream hzChain::Size defstream defstream err 5:err!=Z_OK 6:Return hzerr(E_NOINIT,Could not run deflate process) 7:items items hzChain::Append tmp buf hzChain::Size 8:!gzipped.Size() 9:Return hzerr(E_NODATA,Input %d bytes but no output,orig.Size()) 10:Return E_OK

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 ;
}