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 |
|
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 |
|
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
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Dec 13 21:54:13 CET 2024
Total time taken to generate the page: 0.04128 seconds
|