Hey guys.
Here's my problem:
When I try to run my program I get this error:
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_filebuf::underflow error reading the file
I already looked everywhere and I can't find why this is happening in this particular program.
This program scans a directory for the files there and decompress all of them.
It doesn't have any file type filter because I'm just testing this directory scan code to make it part of this decompress program and there is only compressed files supported by zlib in the folder specified in the path.
I tried to use GDB to find the answer but that didn't went well either.
Here is the last lines executed from GDB:
46 operator T& () const { return *t_; }
(gdb)
boost::iostreams::detail::read_device_impl<boost::iostreams::streambuf_tag>::read<boost::iostreams::filtering_streambuf<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char>, boost::iostreams::public_> > (t=..., s=0x806aa90 "", n=4096)
at /usr/include/boost/iostreams/read.hpp:153
153 0;
(gdb)
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_filebuf::underflow error reading the file
Program received signal SIGABRT, Aborted.
0x0067f402 in __kernel_vsyscall ()
The code of the program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <fstream>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
using namespace std;
using namespace boost::iostreams;
void decompress (string source, string filename)
{
ifstream file(source.c_str(), ios_base::in | ios_base::binary);
ofstream out(filename.c_str(), ios_base::out | ios_base::binary);
filtering_streambuf<input> in;
in.push(zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, out);
}
int main ()
{
string source;
string filename;
const string path = "/home/pablo/testee";
char result;
DIR* dir = opendir(path.c_str());
struct dirent* ent = 0;
while (dir && (ent = readdir(dir)))
{
filename = ent->d_name;
string new_filename = filename;
result = new_filename.find_last_of('.');
if (std::string::npos != result)
{
new_filename.erase(result);
}
new_filename.append(".txt");
source = path + "/" + ent->d_name;
filename = path + "/" + new_filename;
decompress(source, filename);
}
closedir(dir);
return 0;
}
|
I really need help with this.
Thanks in advance.