Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Is there a Zip/UnZip example?
Is there a Zip/UnZip example? [message #37330] Sun, 23 September 2012 03:14 Go to next message
CppMod is currently offline  CppMod
Messages: 11
Registered: February 2011
Location: Plano, TX
Promising Member
I found the zip.h file, but I was looking for a complete example program that does zip and/or unzip. The threads in this forum are rather old, and have some broken links.

Anyone have some zip/unzip code they are willing to share?


611bb927f8731cdc83c3f1eb09e758ac
Re: Is there a Zip/UnZip example? [message #37333 is a reply to message #37330] Sun, 23 September 2012 09:34 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

CppMod wrote on Sun, 23 September 2012 03:14

I found the zip.h file, but I was looking for a complete example program that does zip and/or unzip. The threads in this forum are rather old, and have some broken links.

Anyone have some zip/unzip code they are willing to share?

Hi Howard,

In plugin/zip package are some handy classes for zip format. It can be used like this:
#include <plugin/zip/zip.h>
using namespace Upp;

CONSOLE_APP_MAIN{
	// Compression
	FileZip zip("/tmp/test.zip");
	const char* somedata="some data";
	String otherdata="other data";
	zip.WriteFolder("test", GetSysTime());
	zip.WriteFile(somedata, strlen(somedata), "somedata.txt");
	zip.WriteFile(otherdata, "test/otherdata.txt");
	if(zip.Finish())
		Cout() << "Zip created succesfully\n";
	
	// Decompression
	FileUnZip unzip("/tmp/test.zip");
	while (!(unzip.IsEof() || unzip.IsError())) {
		Cout() << "Path:" << unzip.GetPath() << "\n";
		Cout() << "  Time:" << unzip.GetTime() << "\n";
		if(!unzip.IsFolder()){
			Cout() << "  Size:" << unzip.GetLength() << "\n";
			Cout() << "  Content:" << unzip.ReadFile() << "\n";
		} else
			unzip.SkipFile();
	}
}


Aside from FileZip and FileUnZip there are also in-memory variants StringZip, StringUnZip and MemUnZip that don't read/write files from disk. Their usage is very similar.

Best regards,
Honza
Re: Is there a Zip/UnZip example? [message #37358 is a reply to message #37333] Wed, 26 September 2012 21:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12106
Registered: November 2005
Ultimate Member
Example adopted to reference.

Mirek
Re: Is there a Zip/UnZip example? [message #37799 is a reply to message #37358] Tue, 13 November 2012 19:46 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

BTW, is there a possibility to make streaming unzip with FileZip or any other class? If original file is 1GB large, it is very memory consumable to unzip the whole file into memory.
Re: Is there a Zip/UnZip example? [message #37802 is a reply to message #37799] Wed, 14 November 2012 07:47 Go to previous message
mirek is currently offline  mirek
Messages: 12106
Registered: November 2005
Ultimate Member
bool UnZip::ReadFile(Stream& out, Gate2<int, int> progress = false);

It is true that we now have more "modern" interface style for this (see Zlib class), but Stream& out should work as well...

Mirek

[Updated on: Wed, 14 November 2012 07:47]

Report message to a moderator

Previous Topic: Regexp is not working
Next Topic: How does widget/variable destruction in U++ work?
Goto Forum:
  


Current Time: Fri Nov 22 21:26:51 CET 2019

Total time taken to generate the page: 0.01026 seconds