Thread: .zip, .tar, .tar.gz?

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    118

    .zip, .tar, .tar.gz?

    Is there something in STL that allows me to decompress archives in this format?

    If not, what is the absolute easiest library that can?

    Thanks!
    FlyingIsFun1217

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    those are files, you would have to write a program to decompress them which is a waste of time given there are things like 7-zip which decompresses all those file formats.

    The most the stl will give you is ifstream and ofstream and you'd have to figure out the rest yourself.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The standard C++ library does not include any archive utilities. Boost does, or you can use some other library. I don't know of any offhand, try google.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Boost doesn't have archive utilities either, just compression.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Erhm, yes, sorry. I haven't actually used it myself, so I don't know about the details. http://www.boost.org/libs/iostreams/doc/index.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I would think boost would be overkill. there's zlib though, which does exactly what you want.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Quote Originally Posted by robwhit View Post
    I would think boost would be overkill. there's zlib though, which does exactly what you want.
    Yes, I saw zlib. Only thing is, it seems kinda confusing for what it is. Which is why I mentioned the easy part in the first post.

    Thanks for the help, anything else?
    FlyingIsFun1217

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    zlib is probably about as "easy" as you're going to get. You could look at the manual, which I'm sure you have already done. There's also a How-To of sorts (for C).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    of course, there's the system() way... but not very good.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    But very easy.
    Code:
    system("gunzip file.txt.gz");
    or whatever the command is on your system.

    Using system() is slow, unportable, and sometimes unsecure. But it would let you uncompress a file by executing another program quite easily.

    Rather than system(), you could also use some other platform-specific function to execute your compression program: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Wow... too bad you guys didn't post earlier. I've found the 'cure' to be such!

    Here's How I set it up:

    Code:
    system("cd /usr/share/themes");
    system("gunzip "<<location4<<"");
    system("tar xf "<<location4<<"");
    As you can probably tell though, this gives me errors:

    error: no match for 'operator<<' in '" gunzip" << location4'
    Hmm. Whats wrong here? Somebody had to know...

    And this is going to be a program specific to Xubuntu, so portability is not an issue.

    Thanks again!
    FlyingIsFun1217

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Code:
                    string location4;
    		char yes_or_no3;
    
    		cout<<"Enter the location of your zipped (.tar.gz) theme: ";
    
    		cin>>location4;
    		cin.ignore();
    
    		cout<<"\n\nUnzipping and installing...\n";
    		system("cd /usr/share/themes");
    		system("gunzip "<<location4<<"");
    		system("tar xf "<<location4<<"");
    
    		cout<<"Done! Please use the Theme Selector to apply!";
    		cout<<"Would you like to delete "<<location4<<"? (Y/N): ";
    
    		cin>>yes_or_no3;
    		cin.ignore();
    
    		if (yes_or_no3 == "Y")
    		{
    			cout<<"Deleting "<<location4<<"...\n";
    			remove(location4);
    			cout<<"Successfully deleted "<<location4<<"!";
    		}
    
    		else
    		{
    			return 1;
    		}
    This is my usage, BTW.

    FlyingIsFun1217

  13. #13
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Here's an example showing how to load a bitmap from a zip and display it in SDL. Shouldn't be too hard to figure out how to use zlib from this.

    http://gpwiki.org/index.php/SDL:Tuto...RWops_and_zlib

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Quote Originally Posted by Frobozz View Post
    Here's an example showing how to load a bitmap from a zip and display it in SDL. Shouldn't be too hard to figure out how to use zlib from this.

    http://gpwiki.org/index.php/SDL:Tuto...RWops_and_zlib
    Thanks, but like I said, I've decided to use the system() method.

    My problem still stands, how come I cant use <<string_variable<< in the system command?

    Thanks!
    FlyingIsFun1217

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Because << doesn't concatenate strings. + does.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zipping Folder to a .zip
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 01-06-2002, 09:27 PM