Using Boost for reading zip files
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Using Boost for reading zip files

  1. #1
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Using Boost for reading zip files

    This is continuation of previous thread in my quest for getting something to read the zipped folders I have but since the methodology is different I decided to start a new thread.

    I installed boost and ran a couple of example programs but this one which could have saved my day is not working:
    Code:
    #include <fstream>
    #include <iostream>
    #include <boost/iostreams/filtering_streambuf.hpp>
    #include <boost/iostreams/copy.hpp>
    #include <boost/iostreams/filter/gzip.hpp>
    
    int main() 
    {
    	using namespace std;
    
    	ifstream file("hello.gz", ios_base::in | ios_base::binary);
    	filtering_streambuf<input> in;
    	in.push(gzip_decompressor());
    	in.push(file);
    	boost::iostreams::copy(in, cout);
    }
    The errors are:
    Code:
    1>c:\: error C2065: 'filtering_streambuf' : undeclared identifier
    1>c:\: error C2065: 'input' : undeclared identifier
    1>c:\: error C2065: 'in' : undeclared identifier
    1>c:\: error C2065: 'in' : undeclared identifier
    1>c:\: error C2228: left of '.push' must have class/struct/union
    I just copied this code from boost website. Also, it does not give error with the headers as unrecognized headers at all.

    So, where is this thing going wrong?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,434

    Re: Using Boost for reading zip files

    Quote Originally Posted by Learned View Post
    So, where is this thing going wrong?
    The same thing that is wrong with this program:
    Code:
    #include <iostream>
    
    int main()
    {
       cout << "Hello World";  // error -- cout undefined
    }
    In other words -- namespaces. Those definitions are in a namespace, they are not global names.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Using Boost for reading zip files

    Also, be aware that gzip is not the same thing as zip. gzip is a compression format used on the Internet for data transfer under the HTTP/1.1 protocol. zip is an archiving format for multiple files which may or may not be compressed.

    Mike

  4. #4
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Using Boost for reading zip files

    Quote Originally Posted by MikeAThon View Post
    Also, be aware that gzip is not the same thing as zip. gzip is a compression format used on the Internet for data transfer under the HTTP/1.1 protocol. zip is an archiving format for multiple files which may or may not be compressed.

    Mike
    So, you mean boost is not suitable in reading .zip files?

  5. #5
    Join Date
    Apr 1999
    Posts
    27,434

    Re: Using Boost for reading zip files

    Quote Originally Posted by Learned View Post
    So, you mean boost is not suitable in reading .zip files?
    It is "suitable". The question is do you have a zip decompressor class that is compatible with the boost iostreams library?

    Look at your code -- what makes it uncompress gzip files? Is it the boost::iostreams itself, or is it that gzip_decompressor()? It is the latter, and it's that plug-in that needs to be written or found somewhere. The boost::iostreams library is based on sources and sinks. In this case, the "source" would be a zipped file, and the "sink" is the uncompressed file.

    So nothing stops boost::iostreams from decompressing zip files -- the issue is that do you have the "plug-in" to do it, if not, can you write one based on the "source" and "sink" paradigm?

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; December 1st, 2011 at 09:00 PM.

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Using Boost for reading zip files

    Quote Originally Posted by Learned
    So, you mean boost is not suitable in reading .zip files?
    Based on the sample code from the boost library (which mentions the file extension of .gz meaning gzip), and based on the name of the boost function gzip_decompressor(), I would say "no", the boost library is useless for decompression of .zip files

    Mike

  7. #7
    Join Date
    Apr 1999
    Posts
    27,434

    Re: Using Boost for reading zip files

    Quote Originally Posted by MikeAThon View Post
    Based on the sample code from the boost library (which uses the file extension of .gz meaning gzip), and based on the name of the boost function gzip_decompressor(), I would say "no", the boost library is useless for decompression of .zip files
    Well, it isn't useless unless you write the decompressor that can be plugged into the boost::iostreams classes. Maybe someone has done it, I don't know. But it looks like the boost-iostreams authors left that as "homework" for someone else to do.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Apr 1999
    Posts
    27,434

    Re: Using Boost for reading zip files

    Quote Originally Posted by Learned View Post
    So, you mean boost is not suitable in reading .zip files?
    Learned,

    There are libraries that clearly state they read (and write) .zip archives and files, so if you see "gzip" as the only format it reads and not "zip", it isn't going to work, period.

    Some of these zip libraries are free (InfoZip), while others, you have to pay for since they do much more. Please do a google search for these libraries.

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Using Boost for reading zip files

    Quote Originally Posted by Paul McKenzie View Post
    Some of these zip libraries are free (InfoZip), while others, you have to pay for since they do much more. Please do a google search for these libraries.
    Learned - InfoZip is a good tip and a good find, and the suggestion to Google for other libraries is also a good one.

    In addition, the latest version of the Windows SDK (?? I'm not completely sure of this -- the documentation is a bit vague and perhaps it's only available on a server development SDK??) exposes "Compression API Functions", see http://msdn.microsoft.com/en-us/library/hh437556.aspx
    Quote Originally Posted by MSDN
    The native Compression API includes the following functions.

    CloseCompressor
    CloseDecompressor
    Compress
    CreateCompressor
    CreateDecompressor
    Decompress
    QueryCompressorInformation
    QueryDecompressorInformation
    ResetCompressor
    ResetDecompressor
    SetCompressorInformation
    SetDecompressorInformation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center