//------------------------------------------------------------------------------ void Compressor::startDecompression(void) { try { filtering_istreambuf in; // register decompressor in.push(zlib_decompressor(getZlibParams())); in.push(*istream_); // extract file to buffer std::vector<char> file_buf; back_insert_device< std::vector<char> > b_ins(file_buf); copy(in, b_ins); uncompressedIstream_ = std::shared_ptr<std::istream>(new v_stream(file_buf)); } catch ( const zlib_error &z_err) { uncompressedIstream_.reset(); std::cerr << "Zlib decompression failed with error code: " << z_err.error() << std::endl; throw z_err; } }
void Compression::ZlibDecompress (std::istream& is, std::ostream& os) { char buffer[32]; is.getline (buffer, sizeof(buffer), '#'); int size (atoi (buffer)); if (size == 0) return; filtering_stream<input> fs; fs.push (zlib_decompressor()); fs.push (restrict (is, 0, size)); boost::iostreams::copy(fs, os); // fs.set_auto_close (false); fs.pop (); // Warning filtering stream is closed at destruction causing all underlying device to be clolsed as well. }
bool ZipFileAsset::readAndUnzipFile(char* buffer) { /* for (int i = 0; i < this->getFileDataSize(); i++) { *(buffer + i) = *(m_pDirData + i); } */ stringstream ss; filtering_istreambuf filter; filter.push(zlib_decompressor()); /* string dirDataStr = string_utils::charToString(m_pDirData); ss << "Length: " << dirDataStr.length(); logger::info(ss); ss << "Length FileData: " << getFileDataSize(); logger::info(ss); ss << "--------- START ASSET---------"; logger::info(ss); const char* pDirData = dirDataStr.c_str(); for (int i = 0; i << dirDataStr.length(); i++) { ss << *(pDirData + i); } logger::info(ss); ss << "--------- END ASSET ---------"; logger::info(ss); */ //array_source source(pZipFileAsset->getDirData(), // pZipFileAsset->getFileDataSize()); //array_source source(zipString.c_str(), zipString.length()); string dirDataStr = string_utils::charToString(m_pDirData); ss << "ZipFileAssset-Length: " << dirDataStr.length(); logger::info(ss); ss << "ZipFileAssset-Length FileData: " << getFileDataSize(); logger::info(ss); char* pStart = m_pDirData; int i = 0; while (*(pStart + i)) { i++; }; ss << "ZipFileAssset-dlugosc: " << i; logger::info(ss); int sizeAll = sizeof(m_pDirData); int sizeOne = sizeof(m_pDirData[0]); int sizeRes = sizeAll / sizeOne; // array_source source(dirDataStr.c_str(), dirDataStr.length() + 1); array_source source(getDirData(), getFileDataSize()); // OK // array_source source(*m_pDirData, // *(m_pDirData + this->getFileDataSize() - 1)); filter.push(source); vector<char> vecString; boost::iostreams::copy(filter, boost::iostreams::back_inserter(vecString)); this->debugSaveAsFile(vecString); int position = 0; for (vector<char>::iterator it = vecString.begin(); it != vecString.end(); ++it) { *(buffer + position) = *it; position++; } return true; }