Esempio n. 1
0
Error decompressString(const std::vector<unsigned char>& compressedData,
                       std::string* str)
{
   if (compressedData.empty())
   {
      *str = "";
      return Success();
   }

   size_t dataLen = compressedData.size();
   ByteBuffer srcBuff(dataLen);
   srcBuff.append(compressedData.data(), dataLen);

   // It's unlikely we were able to compress the original data to < 1/2 of it's size.
   // If we did, we can make multiple decompression passes.
   ByteBuffer destBuff(dataLen * 2);

   z_stream zStream;
   size_t remainIn, remainOut;
   makeZStream(srcBuff, destBuff, &remainIn, &remainOut, &zStream);

   int res = inflateInit(&zStream);
   if (res != Z_OK)
      return systemError(res, "ZLib initialization error", ERROR_LOCATION);

   while (res != Z_STREAM_END)
   {
      updateOut(&destBuff, &remainOut, &zStream);

      res = inflate(&zStream, Z_NO_FLUSH);
      destBuff.setDataSize(zStream.total_out);
      if ((res == Z_DATA_ERROR) || (res == Z_NEED_DICT) || (res == Z_MEM_ERROR))
      {
         inflateEnd(&zStream);
         LOG_ERROR_MESSAGE("Could not decompress data\"" +
                           std::string(reinterpret_cast<const char*>(compressedData.data()), dataLen) +
                           "\"");
         return systemError(res, "ZLib inflation error", ERROR_LOCATION);
      }

      updateIn(&srcBuff, &remainIn, &zStream);
   }

   inflateEnd(&zStream);

   *str = destBuff.toString();
   return Success();
}
Esempio n. 2
0
Error compressString(const std::string& toCompress, std::vector<unsigned char>* compressedData)
{
   if (toCompress.empty())
   {
      *compressedData = std::vector<unsigned char>();
      return Success();
   }

   size_t dataLen = toCompress.size();
   ByteBuffer srcBuff(dataLen);
   ByteBuffer destBuff(dataLen);

   srcBuff.append(toCompress);

   z_stream zStream;
   size_t remainIn, remainOut;
   makeZStream(srcBuff, destBuff, &remainIn, &remainOut, &zStream);

   int res = deflateInit(&zStream, Z_BEST_COMPRESSION);
   if (res != Z_OK)
      return systemError(res, "ZLib initialization error", ERROR_LOCATION);

   while (res != Z_STREAM_END)
   {
      updateOut(&destBuff, &remainOut, &zStream);
      res = deflate(&zStream, Z_FINISH);
      destBuff.setDataSize(zStream.total_out);
      if (res == Z_STREAM_ERROR)
      {
         deflateEnd(&zStream);
         LOG_ERROR_MESSAGE("Could not compress string \"" +
                           toCompress + "\"");
         return systemError(res, "ZLib deflation error", ERROR_LOCATION);
      }
      updateIn(&srcBuff, &remainIn, &zStream);
   }

   deflateEnd(&zStream);

   compressedData->assign(destBuff.get(), destBuff.get() + destBuff.dataSize());
   return Success();
}
Esempio n. 3
0
int main(int argc,char *argv[])
{
  IObjContainer ioc;

  isPostProc = false;
  isCPU_time=false;

  parseOptions(argc, argv, ioc);

  if( isCPU_time )
  {
    getWallClockSeconds();
    getCPUSeconds();
  }

  // path/filename was set in setObjProperties()

  // About processing: init() and entry() functions of the
  // base-derived objects are addressed by pointers,
  // where the first call points to init() and than the pointer
  // switches to entry().
  // Objects for Frequency Dist., TimeControl, and QualityControl,
  // respectively, are linked by pointers to the base-derived objects.

  do
  {
    // Do we go for building file names?
    // Processing of a sequence of multiple netCDF files.
    // Or just a single instance for a specified filename.

    // build filenames and sync with date or process single files.
    if( updateIn(ioc.in) )
      break ;  // no more files or an error

  // do all the real stuff
  } while( entry(ioc.vIObj) );

  return finally(ioc);
}