[boost.iostreams] Can't be able to read gzipped file
Hello, During the implementation of a TARFILE module based on Boost.Iostream, I've faced a problem during reading operation of a boost::iostream::filtering_stream<> with a GZip codec. To illustrate it, you will find hereafter a small code snippet that reproduces my problem: namespace io = boost::iostreams ; namespace fs = boost::filesystem ; const fs::path test_file("test.txt.gz") ; const std::string s("Test..................") ; { io::filtering_streamio::output ofilter ; ofilter.push(io::gzip_compressor()) ; ofilter.push(io::file_descriptor_sink( test_file.external_file_string() , std::ios::binary)) ; ofilter << s ; } { io::filtering_streamio::input ifilter ; ifilter.push(io::gzip_decompressor()) ; ifilter.push(io::file_descriptor_source( test_file.external_file_string() , std::ios::binary)) ; std::string rs ; ifilter >> rs ; // <- Here process is blocked in file_description.cpp @ line 145 //boost::scoped_array<char> buffer(new char[512]) ; //const std::streamsize count = io::read(ifilter, buffer.get(), 512) ; } The problem occurs during the reading operation @ line: "ifilter >> rs": the process is blocked in boost/iostreams/src/file_description.cpp @ line 145 ("if (!::ReadFile(pimpl_->handle_, s, n, &result, NULL))") when this line is executed. I've tried to use boost::iostream::read() template function without more success. I've checked the file after the writing operation w/ 7z and everything is fine at this point. I've tried the same code snippet w/ ZLib and BZip2 codecs without trouble. My environment is: Visual C++ 7.1 Boost 1.34.1 Windows XP SP2 Is there any bug in GZip decompressor with the file_descriptor_source? Or I've missed something? Any help will be appreciated. Best regards, Marc VIALA
Marc Viala Perso wrote:
Hello,
During the implementation of a TARFILE module based on Boost.Iostream, I’ve faced a problem during reading operation of a boost::iostream::filtering_stream<> with a GZip codec. To illustrate it, you will find hereafter a small code snippet that reproduces my problem:
...
Is there any bug in GZip decompressor with the file_descriptor_source? Or I’ve missed something?
I'll look into it. -- Jonathan Turkanis CodeRage http://www.coderage.com
Hi Jonathan, Thanks for handling this problem. Just to push more information on that subject, I've just tried, this morning, to replace file_descriptor_source/ file_descriptor_sink by fs::ifstream/fs::ofstream instance in the filtering chain and the same code snippet seems to works, i.e.: { fs::ofstream ofs(test_file, std::ios::binary) ; io::filtering_streamio::output ofilter ; ofilter.push(io::gzip_compressor()) ; ofilter.push(ofs) ; ofilter << s ; } { fs::ifstream ifs(test_file, std::ios::binary) ; io::filtering_streamio::input ifilter ; ifilter.push(io::gzip_decompressor()) ; ifilter.push(ifs) ; std::string rs ; ifilter >> rs ; } Looking forward to hearing from you. Best regards, Marc VIALA
bounces@lists.boost.org] De la part de Jonathan Turkanis Envoyé : vendredi 18 janvier 2008 04:50
During the implementation of a TARFILE module based on Boost.Iostream, Ive faced a problem during reading operation of a boost::iostream::filtering_stream<> with a GZip codec. To illustrate it, you will find hereafter a small code snippet that reproduces my problem:
...
Is there any bug in GZip decompressor with the file_descriptor_source? Or Ive missed something?
I'll look into it.
-- Jonathan Turkanis
Marc Viala Perso wrote:
Hi Jonathan,
Thanks for handling this problem.
Just to push more information on that subject, I've just tried, this morning, to replace file_descriptor_source/ file_descriptor_sink by fs::ifstream/fs::ofstream instance in the filtering chain and the same code snippet seems to works, i.e.:
This is fixed now in branches/iostreams_dev, to be merged into trunk shortly. The following patch should fix 1.34.1: -- Index: file_descriptor.cpp =================================================================== --- file_descriptor.cpp (revision 43122) +++ file_descriptor.cpp (working copy) @@ -144,7 +144,7 @@ DWORD result; if (!::ReadFile(pimpl_->handle_, s, n, &result, NULL)) throw detail::bad_read(); - return static_caststd::streamsize(result); + return result == 0 ? -1 : static_caststd::streamsize(result); } #endif errno = 0; -- Jonathan Turkanis CodeRage http://www.coderage.com
Marc Viala Perso wrote:
During the implementation of a TARFILE module based on Boost.Iostream, I’ve faced a problem during reading operation of a boost::iostream::filtering_stream<> with a GZip codec. To illustrate it, you will find hereafter a small code snippet that reproduces my problem:>
I'm sorry I lost track of this thread. I'm going to try to fix this problem now. Thanks for your patience. -- Jonathan Turkanis CodeRage http://www.coderage.com
bounces@lists.boost.org] De la part de Jonathan Turkanis
I'm sorry I lost track of this thread. I'm going to try to fix this problem now.
Thanks for your patience. [Marc Viala] No problem and Thanks again to handle this point.
Best regards, Marc VIALA
participants (2)
-
Jonathan Turkanis
-
Marc Viala Perso