Пример #1
0
//Read the file and extract its contents to 
//the directory of the zipfile.
int do_extract(char *inputzip)
{
    char *extract_dir = dirname(inputzip);

    if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) ) 
    {
        // ensure directory is created first
        char *dir = (char *) malloc(strlen(extract_dir) + 2);
        if(!dir)
        {
            return 0;
        }

        sprintf(dir, "%s/", extract_dir);
        mkdirs(dir);
        free(dir);
        chdir(extract_dir);
        free(extract_dir);
    }
    if (! openZipFileReader(inputzip)) 
    {
        return 0;
    }

    bool next = isNext();

    // We must have at least one entry
    if (!next) {  
        //sprintf(message,"Error: no entries in zip file.\n");
        return 0;
    }

    while (next) {
        readAndWrite();
        next = isNext();
    }

    closeZipFileReader();
    return 1;
}
Пример #2
0
//Read the file and extract its contents to the
//to the directory of the zipfile.
void do_read(char *inputzip, char* outputdir)
{
  char *extract_dir = NULL;

  if (outputdir != NULL)
      extract_dir = dirname(outputdir);
  else
      extract_dir = dirname(inputzip);

  if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) ) 
  {
     // ensure directory is created first
     char *dir = (char *) malloc(strlen(extract_dir) + 2);
     sprintf(dir, "%s/", extract_dir);
     mkdirs(dir);
     free(dir);

     chdir(extract_dir);
  }
  openZipFileReader(inputzip);
  fprintf(stderr,"Archive: %s\n",inputzip);

  bool next = isNext();

  // We must have atleast one entry
  if (!next) {  
    sprintf(message,"Error: no entries in zip file.\n");
    l_abort(message);
  }

  while (next) {
    readAndWrite();
    next = isNext();
  }

  closeZipFileReader();
  if (remove_input_zip_file) remove(inputzip);
}