diff --git a/src/osgPlugins/gz/ReaderWriterGZ.cpp b/src/osgPlugins/gz/ReaderWriterGZ.cpp index f1fdc9ee0..d548320a0 100644 --- a/src/osgPlugins/gz/ReaderWriterGZ.cpp +++ b/src/osgPlugins/gz/ReaderWriterGZ.cpp @@ -103,6 +103,11 @@ class ReaderWriterGZ : public osgDB::ReaderWriter WriteResult writeFile(ObjectType objectType, const osg::Object* object, const std::string& fullFileName, const osgDB::ReaderWriter::Options* options) const; + + bool read(std::istream& fin, std::string& destination) const; + bool write(std::ostream& fout, const std::string& source) const; + + }; ReaderWriterGZ::ReaderWriterGZ() @@ -169,30 +174,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterGZ::readFile(ObjectType objectType, std::ifstream fin(fileName.c_str()); if (!fin) return ReadResult::ERROR_IN_READING_FILE; - std::streampos start = fin.tellg(); - fin.seekg(0, std::ios::end); - std::streampos end = fin.tellg(); - fin.seekg(start, std::ios::beg); - std::streampos sourceLen = end - start; - /* empty stream into memory, open that, and keep the pointer in a FreeTypeFont for cleanup */ - char* buffer = new char[sourceLen]; - fin.read(reinterpret_cast(buffer), sourceLen); - if (!fin || (static_cast(fin.gcount()) != sourceLen)) - { - osg::notify(osg::WARN)<<" .... the compressed file could not be read from its stream"<0) fout.write((const char*)out, have); + + if (fout.fail()) + { + (void)deflateEnd(&strm); + return false; + } + } while (strm.avail_out == 0); + + /* clean up and return */ + (void)deflateEnd(&strm); + return true; +} + + // now register with Registry to instantiate the above // reader/writer. REGISTER_OSGPLUGIN(GZ, ReaderWriterGZ)