bool FileHandler::setStreamBuffer(bool checkExists) { // redirect stdin or stdout if necesary if (path_ == FileHandler::kStdInDescriptor) { CHECK(flags_ & std::ios::in); std::streambuf* sb = std::cin.rdbuf(); buffer_ = sb; } else if (path_ == FileHandler::kStdOutDescriptor) { CHECK(flags_ & std::ios::out); std::streambuf* sb = std::cout.rdbuf(); buffer_ = sb; } else { // real file if( checkExists && ! fileExists() ) { fprintf(stderr, "ERROR: Failed to find file at %s\n", path_.c_str()); exit(EXIT_FAILURE); } std::string cmd = ""; if( isCompressedFile(cmd) && (! cmd.empty()) ) { buffer_ = openCompressedFile(cmd.c_str()); } else { // open underlying filebuf std::filebuf* fb = new std::filebuf(); fb->open(path_.c_str(), flags_); buffer_ = fb; } } if (!buffer_) { fprintf(stderr, "ERROR:Failed to open file at %s\n", path_.c_str()); exit(EXIT_FAILURE); } this->init(buffer_); return true; }
int ShellUnpacker::unpackAll() { int fileno = 0; int unpackcond = 0; //Condizione di decompressoine unsigned int cicleno = 0; freeCompressedFile(); fileno = openCompressedFile(); if(fileno < 0) return fileno; while(unpackcond == 0) { unpackcond = this->unpackFile(); cicleno++; if(_unpackStubb) _unpackStubb->progressUnpackStubb(cicleno, fileno); if(_stopunpack) { unpackcond = -8; //STOP condition break; } } return unpackcond; }
bool FileHandler::reset() { // move to beginning of file if (fp_ != 0) { //can't seek on a pipe so reopen pclose(fp_); std::string cmd = ""; if (isCompressedFile(cmd) && ! cmd.empty()) buffer_ = openCompressedFile(cmd.c_str()); //reinitialize this->init(buffer_); } else buffer_->pubseekoff(0, std::ios_base::beg); //sets both get and put pointers to beginning of stream return true; }