xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
477 stars 171 forks source link

Implemented means of reading IfcSchema from Streams including non-seekable streams #529

Closed andyward closed 8 months ago

andyward commented 8 months ago

Fixed up Parser edge cases in StepModel/MemoryModel identified in testing. (Was getting NRE rather than sensible exception if header could not be parsed)

MemoryModel already handled non-seekable streams - it implements a patter with a EntityFactoryDelegate which enables a single pass parse. EssentModel does not - it takes an EnityFactory as a constructore param, and this is what forces IModelProvider and IfcStore to require the XbimSchemaVersion when opening a model from a stream. Need to review if we fix that.

Fixed this by implementing a buffered stream which we use internally in IfcStore when an input stream is not Seekable. The buffer just needs to be large enough to hold the header, (typically 1-2KB). As an optimisation the buffering is disabled after we have read the header so we're not copying streaming data unnecessarily.