Link to home
Start Free TrialLog in
Avatar of davinder101
davinder101

asked on

Z_DATA_ERROR ,Windows Programming

Hi Experts

                      I am using Zlib for compressing of my data. It is giving the Z_DATA_ERROR every time.I am not able to figure out the reason for this. Please let me know where I am doing wrong the source code is given below:

bBuffcompress= new BYTE[12*1024*1024];
bBuffUncompress      = new BYTE[12*1024*1024];
DWORD dwUncompressSize =12*1024*1024;
do
{
        DWORD  dwByteRead = 0;
       memset(&drCluChunk,0x00,sizeof(drCluChunk));
       ReadFile(hBackupFile, &drCluChunk, sizeof(drCluChunk),&dwByteRead,NULL);
       dwtotelbyteRead = dwtotelbyteRead + dwByteRead;
       if(drCluChunk.dwTotalCluster != 0)
      {
      DWORD mFTclusteinfile = OnResetClusterLocation(m_BackupParameter._dwRootStartCluster);
      DWORD dwCurrentFilePosition;  
      dwCurrentFilePosition = SetFilePointer(hBackupFile,0,NULL,FILE_CURRENT);
      if(drCluChunk.dwClusterStartFrom == 0)
      {
            //Partition boot record
            DWORD dw =0;
            LARGE_INTEGER      lrMovePos ={0},
            lrCurrentPos ={0};
            lrMovePos.QuadPart = 7;
            SetFilePointerEx(hBackupFile,lrMovePos ,&lrCurrentPos, FILE_CURRENT);
            memset(&ntfsHeader,0x00,sizeof(ntfsHeader));
            BYTE *Buffer = new BYTE[SECTSIZE];
            ReadFile(hBackupFile,Buffer,SECTSIZE,&dw,NULL);      
            memcpy(&ntfsHeader,Buffer,sizeof(ntfsHeader));
            LARGE_INTEGER      lrMovePos1 ={0},
            lrCurrentPos1 ={0};
            lrMovePos1.QuadPart = dwCurrentFilePosition;
            SetFilePointerEx(hBackupFile,lrMovePos1,&lrCurrentPos1,FILE_BEGIN);

      }
             if(mFTclusteinfile !=0)
      {
            DWORD dwReturnValue = 0;
            DWORD comprssbuffsize = 0;
            LARGE_INTEGER      lrMovePos ={0},
            lrCurrentPos ={0};
            lrMovePos.QuadPart = mFTclusteinfile;
            SetFilePointerEx(hBackupFile,lrMovePos ,&lrCurrentPos, FILE_CURRENT);
            bBuffcompress      = new BYTE[drCluChunk.dwCompressSize];
         ReadFile(hBackupFile,bBuffcompress,drCluChunk.dwCompressSize,&dwReturnValue,NULL);
int nFlag = uncompress(bBuffUncompress,&dwUncompressSize,bBuffcompress,drCluChunk.dwCompressSize);
}


nFlag gives (-3) the Z_DATA_ERROR.


PLease help me out  I am stuck here.
ASKER CERTIFIED SOLUTION
Avatar of masheik
masheik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

  That error occurs if the data input is corrupted...

  Reference can be found here.

  http://www.zlib.net/zlib_how.html

  Z_DATA_ERROR indicates that inflate() detected an error in the zlib compressed data format,
  which means that either the data is not a zlib stream to begin with, or that the data was corrupted
  somewhere along the way since it was compressed. The other error to be processed is  
  Z_MEM_ERROR, which can occur since memory allocation is deferred until inflate() needs it, unlike
  deflate(),whose memory is allocated at the start by deflateInit().