MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / stream2

Function stream2

src/ifcopenshell-python/ifcopenshell/__init__.py:327–362  ·  view source on GitHub ↗

Streams the content of a file path from disk, yielding each instance as a dictionary. :param path: Input file path :param mmap: Open the file contents using memory mapping :param page_size: Open file in python and feed chunks to the parser. :yield: Entity instance dictionaries

(path: Union[Path, str], mmap: bool = False, page_size: int = 0)

Source from the content-addressed store, hash-verified

325
326
327def stream2(path: Union[Path, str], mmap: bool = False, page_size: int = 0):
328 """Streams the content of a file path from disk, yielding each instance
329 as a dictionary.
330
331 :param path: Input file path
332 :param mmap: Open the file contents using memory mapping
333 :param page_size: Open file in python and feed chunks to the parser.
334
335 :yield: Entity instance dictionaries
336 """
337 if page_size:
338 import builtins
339
340 f = builtins.open(path, encoding="ascii")
341 strm = ifcopenshell_wrapper.InstanceStreamer()
342 strm.pushPage(f.read(page_size))
343 finished = False
344 while True:
345 while strm.hasSemicolon():
346 if inst := strm.readInstancePy():
347 yield inst
348 else:
349 finished = True
350 break
351 if finished:
352 break
353 else:
354 if data := f.read(page_size):
355 strm.pushPage(data)
356 else:
357 break
358 else:
359 streamer = ifcopenshell_wrapper.InstanceStreamer(str(path), mmap)
360 while streamer:
361 if inst := streamer.readInstancePy():
362 yield inst
363
364
365def stream2_from_string(data: str) -> Generator[dict]:

Callers

nothing calls this directly

Calls 5

pushPageMethod · 0.95
hasSemicolonMethod · 0.95
openMethod · 0.80
InstanceStreamerMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected