From Chuck Seberino, "have a fix for the reading code in trunk/src/osgPlugins/gz/ReaderWriterGZ.cpp. It seems that the std::istream::readsome method on windows is a no-op (for files. After much head scratching and research I was able to figure out what was going on. I am submitting a fix to replace readsome with read() and gcount(). This change is for all platforms. The previous implementation works fine under linux and OSX, so if you would rather keep things the way they are you can just #ifdef for non-WIN32.

I also added openmode flags to the ifstream constructor, since they were needed to get proper reading as well as a typo fix."
This commit is contained in:
Robert Osfield
2010-03-22 13:13:22 +00:00
parent 8b66d5348e
commit 8a39ece376

View File

@@ -173,7 +173,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterGZ::readFile(ObjectType objectType,
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
std::ifstream fin(fileName.c_str());
std::ifstream fin(fileName.c_str(), std::ios::binary|std::ios::in);
if (!fin) return ReadResult::ERROR_IN_READING_FILE;
@@ -251,7 +251,7 @@ bool ReaderWriterGZ::read(std::istream& fin, std::string& destination) const
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit2(&strm,
15 + 32 // autodected zlib or gzip header
15 + 32 // autodetected zlib or gzip header
);
if (ret != Z_OK)
return false;
@@ -259,7 +259,8 @@ bool ReaderWriterGZ::read(std::istream& fin, std::string& destination) const
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fin.readsome((char*)in, CHUNK);
fin.read((char*)in, CHUNK);
strm.avail_in = fin.gcount();
if (fin.fail())
{