zip unzip it

yes, i used a line from a daft punk song

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 2434 Views - Last Post: 22 March 2011 - 09:46 AM Rate Topic: -----

#16 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: zip unzip it

Posted 16 August 2010 - 10:21 AM

Sanity check: zlib is a compression library. Packing up a folder into a single file is archiving. You understand these are orthogonal actions, right?
Was This Post Helpful? 0
  • +
  • -

#17 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 16 August 2010 - 10:35 AM

View PostOler1s, on 16 August 2010 - 12:21 PM, said:

Sanity check: zlib is a compression library. Packing up a folder into a single file is archiving. You understand these are orthogonal actions, right?


I may have failed the sanity check and need to make a will save.

I must admit the post was hard to understand at first as I had not heard that word, but that is neither here nor there.

That said, I see how they are not necessarily one and the same although related (I think that was what you were shooting for when you said orthogonal). If you would, please explain that to me a little more. Mostly because I assumed that the zlib library handled both processes (of course in a way that may be hidden from me).

As per my search on [how to make zip files in c++], I came across this list of things. Assuming that these things were correct, I went on to notice that they mentioned the zlib library (one of them mentioned minizip which I also downloaded).

I'm almost sure I'm missing something here, though, so please correct me.

By the way, the input here is helping me greatly.

*edit*

I noticed this upon further research. Would this be my needed item?

This post has been edited by omochan: 16 August 2010 - 10:37 AM

Was This Post Helpful? 0
  • +
  • -

#18 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: zip unzip it

Posted 16 August 2010 - 11:00 AM

Quote

That said, I see how they are not necessarily one and the same although related (I think that was what you were shooting for when you said orthogonal).
No. You can substitute the word independent for orthogonal if you wish. Archiving and compression have no intrinsic relationship to each other. One does not imply the other. For example, when you browse the internet, often, data is sent compressed. There is no archiving involved. All data is simply compressed. Or consider packed files for games. The primary purpose of this packing is to create an efficient archive format. No compression may be involved.

Quote

Mostly because I assumed that the zlib library handled both processes
No. zlib is dedicated to compression.

Quote

I went on to notice that they mentioned the zlib library (one of them mentioned minizip which I also downloaded). I'm almost sure I'm missing something here, though, so please correct me.
Yes. A zip file like on Windows is a specific format. Zipping (and the inverse for unzipping) allows for both compression and archiving. two things. Of course, to make a compatible zip file, you need to compress and archive just like all other files. There is a standard for this.

The compression part of ZIP allows for a few different methods, one of which is DEFLATE (most widely compatible, basically). zlib implements DEFLATE as part of its own compression implementation, which is why if you were writing a zip program, you might be interested in zlib.

But you obviously aren't done here. All you get from zlib is a compression implementation. You of course have to write your own code to read and archive files. This is why you are stuck. You are looking for a complete zip implementation, but all you get is DEFLATE, and the rest is left to you.

So you need to find a tool or library that handles zipping, as opposed to just deflate compression. The link you got seems to be one option. Another is something like zziplib. And so on.
Was This Post Helpful? 1
  • +
  • -

#19 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,558
  • Joined: 23-August 08

Re: zip unzip it

Posted 16 August 2010 - 11:00 AM

View Postomochan, on 16 August 2010 - 11:04 AM, said:

View PostJackOfAllTrades, on 16 August 2010 - 11:56 AM, said:

Looks like Project->Properties->C/C++ General->Paths and Symbols, the Includes Tab and Libraries Tab


I was thinking that. I'm trying to figure out how to include the directory as a whole. Hm...


There's another tab to the right of Libraries...
Was This Post Helpful? 1
  • +
  • -

#20 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 16 August 2010 - 12:19 PM

View PostOler1s, on 16 August 2010 - 01:00 PM, said:

Quote

That said, I see how they are not necessarily one and the same although related (I think that was what you were shooting for when you said orthogonal).
No. You can substitute the word independent for orthogonal if you wish. Archiving and compression have no intrinsic relationship to each other. One does not imply the other. For example, when you browse the internet, often, data is sent compressed. There is no archiving involved. All data is simply compressed. Or consider packed files for games. The primary purpose of this packing is to create an efficient archive format. No compression may be involved.

Quote

Mostly because I assumed that the zlib library handled both processes
No. zlib is dedicated to compression.

Quote

I went on to notice that they mentioned the zlib library (one of them mentioned minizip which I also downloaded). I'm almost sure I'm missing something here, though, so please correct me.
Yes. A zip file like on Windows is a specific format. Zipping (and the inverse for unzipping) allows for both compression and archiving. two things. Of course, to make a compatible zip file, you need to compress and archive just like all other files. There is a standard for this.

The compression part of ZIP allows for a few different methods, one of which is DEFLATE (most widely compatible, basically). zlib implements DEFLATE as part of its own compression implementation, which is why if you were writing a zip program, you might be interested in zlib.

But you obviously aren't done here. All you get from zlib is a compression implementation. You of course have to write your own code to read and archive files. This is why you are stuck. You are looking for a complete zip implementation, but all you get is DEFLATE, and the rest is left to you.

So you need to find a tool or library that handles zipping, as opposed to just deflate compression. The link you got seems to be one option. Another is something like zziplib. And so on.


Thank you so much for that answer. Apologies for the delay as I was at lunch at the time. I will look into zziplib.

If I might ask a question, why or how would someone use something like zlib simply to compress an item? Wouldn't there need to be something to decompress or is that simply left to the client computer at which the files arrive?

Admittedly, I don't need to decompress or unarchive, but it seems I will need more if I wish to archive (which is the other half of my endeavor).

Again, thank you.


View PostJackOfAllTrades, on 16 August 2010 - 01:00 PM, said:

View Postomochan, on 16 August 2010 - 11:04 AM, said:

View PostJackOfAllTrades, on 16 August 2010 - 11:56 AM, said:

Looks like Project->Properties->C/C++ General->Paths and Symbols, the Includes Tab and Libraries Tab


I was thinking that. I'm trying to figure out how to include the directory as a whole. Hm...


There's another tab to the right of Libraries...


I did check that out and added it immediately. At times, I post things only to find the answer moments later. Thank you for the hint, though.


This is good. With people like you guys helping, my c++ fu will be strong in no time.

[edit]
I thought it might be good to tell you what dev tool I am using, so in that vein, I was talking to gabehabe today and picked up [Code::Blocks]. I'm not sure if that helps with these questions, but I know that IDEs can vary on how to implement things from time to time and it's hard to give help without complete information.

This post has been edited by omochan: 16 August 2010 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#21 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: zip unzip it

Posted 16 August 2010 - 01:20 PM

Quote

If I might ask a question, why or how would someone use something like zlib simply to compress an item?
You can use zlib to decompress as well. It implements both the compression and decompression algorithms.

But let's consider in which compression only makes sense. For example, server sending data. For example, an HTTP server, to serve webpages. In this case, the server is only interested in compressing and sending data. What is done with that data is left to the client.
Was This Post Helpful? 1
  • +
  • -

#22 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 17 August 2010 - 10:21 AM

View PostOler1s, on 16 August 2010 - 03:20 PM, said:

Quote

If I might ask a question, why or how would someone use something like zlib simply to compress an item?
You can use zlib to decompress as well. It implements both the compression and decompression algorithms.

But let's consider in which compression only makes sense. For example, server sending data. For example, an HTTP server, to serve webpages. In this case, the server is only interested in compressing and sending data. What is done with that data is left to the client.


I see. Thank you for that info. My end goal is to create a file with a certain archive format, so for my purposes, I don't believe compression will be enough.

If you have used zip_utils before, do you think it would be possible to replace the .zip extension with another one?
Was This Post Helpful? 0
  • +
  • -

#23 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: zip unzip it

Posted 17 August 2010 - 10:56 AM

Quote

If you have used zip_utils before, do you think it would be possible to replace the .zip extension with another one?
I haven't used zip_utils.

I'm not sure what you find relevant from the .zip extension is. It's just a part of the filename. Use another extension if you like, such as .foo or .bar.

This post has been edited by Oler1s: 17 August 2010 - 10:57 AM

Was This Post Helpful? 1
  • +
  • -

#24 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 17 August 2010 - 12:05 PM

To explain myself, the ultimate goal happens in these steps:

  • list file directory
  • pick one directory out of the list
  • zip/archive that directory
  • change the file extension from .zip to the relevant extension


From the item I read about zip_utils, I think it only outputs .zip files, but I'm not sure if someone somewhere has tried to use another extension before and not knowing this, I thought I would ask. If it hasn't been attempted, I'll just try it myself and post my results for anyone else here that might ask a similar question in the future.

As for the four steps I listed above, I have covered the [list file directory] item. My next goal is to get the archiving step handled as I am sure that step two is simple "hey, user, can you type that directory you want zipped in this here box...." and off they go.

I hope I'm not being confusing or unclear and thank you picking up on this topic. I really appreciate you, JackofAllTrades and Anarion for all of the help and insight you've given me so far.
Was This Post Helpful? 0
  • +
  • -

#25 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: zip unzip it

Posted 17 August 2010 - 12:42 PM

Quote

From the item I read about zip_utils, I think it only outputs .zip files
Looking at the snippet examples on that webpage, I see evidence of the opposite.

1. HZIP hz = CreateZip("simple1.zip",0);
2. hz = OpenZip(zipbuf, ziplen, 0);

So the only way you get a .zip extension is if you explicitly take steps to create a file with this extension.
Was This Post Helpful? 1
  • +
  • -

#26 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 17 August 2010 - 01:51 PM

View PostOler1s, on 17 August 2010 - 02:42 PM, said:

Quote

From the item I read about zip_utils, I think it only outputs .zip files
Looking at the snippet examples on that webpage, I see evidence of the opposite.

1. HZIP hz = CreateZip("simple1.zip",0);
2. hz = OpenZip(zipbuf, ziplen, 0);

So the only way you get a .zip extension is if you explicitly take steps to create a file with this extension.


Point noted (and duly so). That said, I will try it and see how it goes. If I can make it any archive type, that cuts out a whole step for me (which is wonderful).
Was This Post Helpful? 0
  • +
  • -

#27 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 19 November 2010 - 10:13 AM

Sorry about the severe delay of communication, but I got dragged into content dev and such for a while at work (a long while) and haven't been able to get back to finishing this app yet.

That said, I found out yesterday after sending an email to the R&D team at my company that this is what they use for their programs and plugins:

Quote

Whatever language lets your plugin be a COM object and communicate with another COM object.

The most common and simple to use are all .NET languages; but in the past we have developed C++ plugins as well.


In short, I can use C++, but don't have to. I'm wondering if I should continue anyway for my own education. Since I've already started and all.

What are your thoughts, C++ ninjas?

This post has been edited by omochan: 19 November 2010 - 10:13 AM

Was This Post Helpful? 0
  • +
  • -

#28 omochan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: zip unzip it

Posted 22 March 2011 - 09:46 AM

I'm updating as I finally got back to the program after months -- MONTHS -- of other crap going on.

I got the idea for how to list the directories (as you may or may not know). After playing around for a while, I have a question -- and it's even specific!

I'm trying to get user input and process that input into a function that will spit out a dir list. Thanks in large part to Gabehabe, this what the main looks like:

int main(){
    string spdir;
    const char *sdir;
	listdir ("C:\\Documents and Settings\\...");
	cout << "Choose a folder from the list.";
	getline (cin, spdir);
	stringstream (spdir) >> sdir;
	listdir (sdir);
	return 0;
}



If you want an idea, this is what the listdir function looks like:

void listdir (const char *path)
{
    // first off, we need to create a pointer to a directory
    DIR *pdir = NULL; // remember, it's good practice to initialise a pointer to NULL!
    pdir = opendir (path); // "." will refer to the current directory
    struct dirent *pent = NULL;
    if (pdir == NULL) // if pdir wasn't initialised correctly
    { // print an error message and exit the program
        printf ("\nERROR! pdir could not be initialised correctly");
        return; // exit the function
    } // end if

    while (pent = readdir (pdir)) // while there is still something in the directory to list
    {
        if (pent == NULL) // if pent has not been initialised correctly
        { // print an error message, and exit the program
            printf ("\nERROR! pent could not be initialised correctly");
            return; // exit the function
        }
        // otherwise, it was initialised correctly. let's print it on the console:
        printf ("%s\n", pent->d_name);
    }

    // finally, let's close the directory
    //closedir (pdir);
}



The listing runs ok. I added the includes for cin, cout, and streamstring. The idea is to take the user input and append it to the longer directory in listdir WITHOUT someone having to type the full path. Something like just typing "this" instead of "C:\Documents and Settings\folder\folder\folder\this\".

Ideas?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2