Jump to content

  • Log In with Google      Sign In   
  • Create Account


reading zip files with zziplib


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 rogerdv   Members   -  Reputation: 161

Like
1Likes
Like

Posted 05 March 2012 - 02:04 PM

Im trying to implement zip archive support based on zziplib, but I cant find any documentation describing how to read the archive contents and then opening a stored file. Can somebody give me a help with this?

Sponsor:

#2 GuyWithBeard   Members   -  Reputation: 804

Like
3Likes
Like

Posted 05 March 2012 - 02:36 PM

This code is taken, more or less, straight out of my game engine. It shows how to open a zip archive and process every file in it.

bool ResourcePack::loadArchive(const std::string& archivePath)
{
ZZIP_DIR* dir = zzip_dir_open(archivePath.c_str(), 0);
void* data = NULL;
// Open the archive root directory.
if (dir)
{
  ZZIP_DIRENT dirent;
  // Loop through the files in the archive.
  while(zzip_dir_read(dir, &dirent))
  {
   ZZIP_FILE* fp = zzip_file_open(dir, dirent.d_name, 0);
   if (fp)
   {  
	// File opened, allocate memory for it and read it into data.
	data = (void*) malloc(dirent.st_size);
	zzip_ssize_t len = zzip_file_read(fp, data, dirent.st_size);
	zzip_file_close(fp);
	/* do things with data ... */
	free(data);
   }
   else
   {
	zzip_dir_close(dir);
	return false;
   }
  }
  zzip_dir_close(dir);
}
else
{
  return false;
}
return true;
}

I hope you find the code helpful.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS