00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00036 #include "OpenCLibzheader.h"
00037 
00038 
00039 
00040 
00041 void Error(const char * msg)
00042 {
00043     printf( " %s\n",  msg);
00044     getchar();
00045     getchar();
00046     exit(1);
00047 }
00048 
00049 
00050 
00051 
00052 
00053 void GzUnCompress(gzFile   in, FILE     * out)
00054 
00055 {
00056     static char buf[BUFLEN];
00057     int len;
00058     int err;
00059 
00060     for (;;)
00061     {
00062         len = gzread(in, buf, sizeof(buf)); 
00063         if (len < 0) Error (gzerror(in, &err));
00064         if (len == 0) break;
00065 
00066         if ((int)fwrite(buf, 1, (unsigned)len, out) != len)
00067         {
00068             Error("failed fwrite");
00069         }
00070     }
00071    if (fclose(out)) Error("failed fclose");
00072 
00073    if (gzclose(in) != Z_OK) 
00074 
00075    Error("failed gzclose");
00076 
00077 
00078 
00079 }
00080 
00081 
00082 
00083 
00084 
00085 
00086 void FileUnCompress( char  * file )
00087 
00088 {
00089     static char buf[MAX_NAME_LEN];
00090     char *infile, *outfile;
00091     FILE  *out;
00092     gzFile in;
00093     char choice[3];
00094     uInt len = (uInt)strlen(file);
00095     strcpy(buf, file);
00096 
00097     if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0)
00098     {
00099         infile = file;
00100         outfile = buf;
00101         outfile[len-3] = '\0'; 
00102     }
00103     else
00104     {
00105         outfile = file;
00106         infile = buf;
00107         strcat(infile, GZ_SUFFIX); 
00108     }
00109     in = gzopen(infile, "rb"); 
00110 
00111     if (in == NULL)
00112     {
00113 
00114       Error("file not found ...try again \n");
00115 
00116     }
00117     out = fopen(outfile, "wb"); 
00118     if (out == NULL)
00119     {
00120     gzclose(in);       
00121     }
00122 
00123     GzUnCompress(in, out);
00124 
00125     printf("do you want to delete the original file (y /n) \n");
00126 
00127     scanf("%s",choice);
00128 
00129     if(choice[0] == 'y')
00130     unlink(file);
00131     printf(" Congrats .... uncompression done ...u can find uncompressed file in the same directory as of the source file\n");
00132 
00133 }
00134 
00135