Posted on 2008-03-28 04:04:25-07 by dpramanik
Uncompress returns -3
Here goes my code
This method reads the local header ZIPFILE * readZipData(FILE *fp) { struct ZIPFILE * pZip = NULL; int tempData; short int tempShortInt; struct ZipHeader *header = NULL; fseek(fp,-4,SEEK_CUR); int *filePos = (int*) malloc(sizeof(int)); *filePos = ftell(fp); header = (struct ZipHeader*)malloc(sizeof(struct ZipHeader)); fread(&tempData,sizeof(int),1,fp); header.localHeader = tempData; fread(&tempShortInt,sizeof(short int),1,fp); header-version = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-genPurposeFlag = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-compressionMethod = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-lastModFileTime = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-lastModFileDate = tempShortInt; fread(&tempData,sizeof(int),1,fp); header-crc = tempData; fread(&tempData,sizeof(int),1,fp); header-compressedSize = tempData; fread(&tempData,sizeof(int),1,fp); header-uncompressedSize = tempData; fread(&tempShortInt,sizeof(short int),1,fp); header-fileNameLength = tempShortInt; fread(&tempShortInt,sizeof(short int),1,fp); header-extraFieldLength = tempShortInt; pZip = (struct ZIPFILE*) malloc(sizeof(struct ZIPFILE)); pZip-FileName = readFileName(header-fileNameLength,fp); pZip-Position = *filePos; pZip-Header = header; pZip-CompressRatio = (1-((float)header-compressedSize/(float)header-uncompressedSize)) * 100; pZip-FileData = readFileData(fp,header-compressedSize,header-extraFieldLength); if(header-genPurposeFlag & 0x4) fseek(fp,12,SEEK_CUR); return pZip; } This reads the compressed file data BYTE * readFileData(FILE *fp, int fileLength, int bytesToSkip) { BYTE * fileData = NULL; if(bytesToSkip 0) fseek(fp,bytesToSkip,SEEK_CUR); fileData = (BYTE *) calloc(fileLength,1); int index = 0; while(index != fileLength) { fileData[index++] = fgetc(fp); } // fread((BYTE*)fileData,fileLength,1,fp); return fileData; } I also read the centrla directory then when I try to call uncompress using unsigned long actualLen = pData-Header-uncompressedSize; BYTE *pActualData = NULL; pActualData = (BYTE*)malloc(pData-Header-uncompressedSize); pByteData points to the contents of compressed file int i = uncompress(pActualData,&actualLen,pByteData,compressedSize); When this is executed it returns -3 from inflate method basically it returns from this code inside +inflate method if ( #endif ((BITS(8) << 8) + (hold 8)) % 31) { strm-msg = (char *)"incorrect header check"; ----------------- +------------- state-mode = BAD; break; I hope this will give enough information whats goin wroing....Please let me know what i'm doing wro +ng
NOTE:: SYNTAX may be wrong as the editor didn't allowed pointer indirection character
Direct Responses: 7491 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.