From 8a39ece3763c73ca5fe2ac6434d968401bf9ee2d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Mar 2010 13:13:22 +0000 Subject: [PATCH] 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." --- src/osgPlugins/gz/ReaderWriterGZ.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/gz/ReaderWriterGZ.cpp b/src/osgPlugins/gz/ReaderWriterGZ.cpp index 073087dac..d07b9fa6f 100644 --- a/src/osgPlugins/gz/ReaderWriterGZ.cpp +++ b/src/osgPlugins/gz/ReaderWriterGZ.cpp @@ -173,7 +173,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterGZ::readFile(ObjectType objectType, osg::ref_ptr local_opt = options ? static_cast(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()) {