// (80 bytes header + 4 bytes facet count + 50 bytes for one facet);
// thus assume files shorter than 134 as Ascii without probing
// (probing may bring stream to fail state if EOF is reached)
- bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream));
+ bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream, true));
Standard_ReadLineBuffer aBuffer (THE_BUFFER_SIZE);
//purpose :
//==============================================================================
-Standard_Boolean RWStl_Reader::IsAscii (Standard_IStream& theStream)
+Standard_Boolean RWStl_Reader::IsAscii (Standard_IStream& theStream,
+ const bool isSeekgAvailable)
{
// read first 134 bytes to detect file format
char aBuffer[THE_STL_MIN_FILE_SIZE];
return true;
}
- // put back the read symbols
- for (std::streamsize aByteIter = aNbRead; aByteIter > 0; --aByteIter)
+ if (isSeekgAvailable)
{
- theStream.unget();
+ // get back to the beginning
+ theStream.seekg(0, theStream.beg);
+ }
+ else
+ {
+ // put back the read symbols
+ for (std::streamsize aByteIter = aNbRead; aByteIter > 0; --aByteIter)
+ {
+ theStream.unget();
+ }
}
// if file is shorter than size of binary file with 1 facet, it must be ascii
const Message_ProgressRange& theProgress);
//! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200).
- //! The function attempts to put back the read symbols to the stream which thus must support ungetc().
+ //! If the stream does not support seekg() then the parameter isSeekgAvailable should
+ //! be passed as 'false', in this case the function attempts to put back the read symbols
+ //! to the stream which thus must support ungetc().
//! Returns true if the stream seems to contain Ascii STL.
- Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream);
+ Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream,
+ const bool isSeekgAvailable);
//! Reads STL data from binary stream.
//! The stream must be opened in binary mode.