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)
| 325 | |
| 326 | |
| 327 | def 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 | |
| 365 | def stream2_from_string(data: str) -> Generator[dict]: |
nothing calls this directly
no test coverage detected