[iostreams] WinRar cannot read zlib archive
Hi there I just have a simple question regarding the format of a zlib
archive. Somehow WinRar cannot read the archive. If I use the simple
example application provided in the zlib distribution WinRar is able
to read it. This makes me wondering what difference is in the archive
generated by boost::iostreams?
Here is my example code which works fine. I using VC7.1 and Boost 1.33
#include <iostream>
#define BOOST_IOSTREAMS_NO_LIB
#include
Christian Henning wrote:
Hi there I just have a simple question regarding the format of a zlib archive. Somehow WinRar cannot read the archive.
What format does WinRar expect? The zlib_compressor compresses data using the ZLIB format (http://www.ietf.org/rfc/rfc1950.txt).
If I use the simple example application provided in the zlib distribution WinRar is able to read it.
Which sample application?
This makes me wondering what difference is in the archive generated by boost::iostreams?
Here is my example code which works fine. I using VC7.1 and Boost 1.33
#include <iostream>
#define BOOST_IOSTREAMS_NO_LIB
#include
#include #include namespace io = boost::iostreams;
int _tmain(int argc, _TCHAR* argv[]) { { io::filtering_ostream out; out.push( io::zlib_compressor() ); out.push( io::file_sink( "hello.zip" ));
This might be the problem. zlib_compressor does not write data in the "ZIP" archive format (http://www.pkware.com/business_and_developers/developer/appnote/). You can use zlib_[de]compressor to implement a zip archiver, but if you try to open a file in the ZLIB format with a utility that expects a ZIP file, it won't work. I may add support for zip files eventually, but I haven't decided on an interface, and I'm not even sure whether it should go in the iostreams library or in a new library.
out << "Hello boost::iostreams";
//close the file }
io::filtering_istream in; in.push( io::zlib_decompressor() ); in.push( io::file_source( "hello.zip" ));
std::string strMessage;
std::getline( in, strMessage );
std::cout << strMessage << std::endl;
return 0; }
Besides the problem, seems that boost::iostream is an amazing lib and a huge contribution for the C++ community.
Thanks!
Thanks, Christian
-- Jonathan Turkanis www.kangaroologic.com
When I use this little test program, taken from the zlib examples. WinRar doesn't have any problem opening it. The generated file "chh.gz" is 26 bytes. int main() { gzFile file; file = gzopen( "chh.gz", "wb"); gzputc(file, 'h'); gzputs(file, "ello" ); gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ gzclose(file); return 0; } Using the iostreams I think, and I might be wrong, should generate the same file using this test program: int main() { io::filtering_ostream out; out.push( io::zlib_compressor() ); out.push( io::file_sink( "chh.gz", std::ios::binary )); out << "hello"; return 0; } Here the file is 13 bytes. So I guess the header or footer is wrong. Greets, Christian
Christian Henning wrote:
When I use this little test program, taken from the zlib examples. WinRar doesn't have any problem opening it. The generated file "chh.gz" is 26 bytes.
int main() { gzFile file;
file = gzopen( "chh.gz", "wb");
Okay, you're writing data in the gzip format, which has a different headder and footer than the zlib format, even though the body of the compressed data is the same. For this, you should be using the gzip filters: www.boost.org/libs/iostreams/doc/index.html?path=4.2.2.11.
gzputc(file, 'h'); gzputs(file, "ello" );
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file);
return 0; }
Using the iostreams I think, and I might be wrong, should generate the same file using this test program:
int main() { io::filtering_ostream out; out.push( io::zlib_compressor() );
try: out.push( io::gzip_compressor() );
out.push( io::file_sink( "chh.gz", std::ios::binary ));
out << "hello";
return 0; }
Here the file is 13 bytes. So I guess the header or footer is wrong.
Greets, Christian
-- Jonathan Turkanis www.kangaroologic.com
Thanks, I changed for gzip and now its working. The file 25 bytes (1 bytes is still missing ) and Winrar can read it. Christian
Christian Henning wrote:
Thanks, I changed for gzip and now its working.
Good.
The file 25 bytes (1 bytes is still missing ) and Winrar can read it.
The exact size of the header depends on which parameters you supply (e.g., file_name, comment).
Christian
-- Jonathan Turkanis www.kangaroologic.com
participants (2)
-
Christian Henning
-
Jonathan Turkanis