void ClusterImpl::init_from_stream(ifstream& in, offset_type offset) { log_trace("init_from_stream"); in.seekg(offset); clear(); char c; in.get(c); setCompression(static_cast<CompressionType>(c)); switch (static_cast<CompressionType>(c)) { case zimcompDefault: case zimcompNone: startOffset = read_header(in); startOffset += sizeof(char) + offset; set_lazy_read(&in); break; case zimcompZip: { #ifdef ENABLE_ZLIB log_debug("uncompress data (zlib)"); zim::InflateStream is(in); is.exceptions(std::ios::failbit | std::ios::badbit); read_header(is); read_content(is); #else throw std::runtime_error("zlib not enabled in this library"); #endif break; } case zimcompBzip2: { #ifdef ENABLE_BZIP2 log_debug("uncompress data (bzip2)"); zim::Bunzip2Stream is(in); is.exceptions(std::ios::failbit | std::ios::badbit); read_header(is); read_content(is); #else throw std::runtime_error("bzip2 not enabled in this library"); #endif break; } case zimcompLzma: { #ifdef ENABLE_LZMA log_debug("uncompress data (lzma)"); zim::UnlzmaStream is(in); is.exceptions(std::ios::failbit | std::ios::badbit); read_header(is); read_content(is); #else throw std::runtime_error("lzma not enabled in this library"); #endif break; } default: log_error("invalid compression flag " << c); in.setstate(std::ios::failbit); break; } }
void f_exit(ifstream& f) { f.setstate(ios::badbit); }