diff --git a/README.md b/README.md index 136a667..091dc49 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,6 @@ ifcurl render "ifc://..." -o output.png Use as a library: ```python -import os, tempfile import ifcopenshell from ifcurl import IfcUrl, fetch_ifc from ifcurl.render import render @@ -98,15 +97,7 @@ url = IfcUrl.parse( "?path=models/building.ifc&selector=IfcWall&visibility=ghost" ) hexsha, ifc_bytes = fetch_ifc(url) # hexsha is stable even for mutable refs - -# ifcopenshell.open() requires a file path, not bytes -tmp_fd, tmp_path = tempfile.mkstemp(suffix=".ifc") -try: - os.write(tmp_fd, ifc_bytes) - os.close(tmp_fd) - model = ifcopenshell.open(tmp_path) -finally: - os.unlink(tmp_path) +model = ifcopenshell.file.from_string(ifc_bytes.decode()) png = render(model, selector=url.selector, clips=url.clips or None, camera=url.camera, fov=url.fov, visibility=url.visibility) diff --git a/ifcurl/service.py b/ifcurl/service.py index c8883a1..3216db7 100644 --- a/ifcurl/service.py +++ b/ifcurl/service.py @@ -38,7 +38,6 @@ from __future__ import annotations import hashlib import ipaddress import os -import tempfile import threading import time @@ -225,18 +224,10 @@ def _t4m_put(url: str, png: bytes) -> None: # --------------------------------------------------------------------------- def _load_model(ifc_bytes: bytes) -> ifcopenshell.file: - tmp_fd, tmp_path = tempfile.mkstemp(suffix=".ifc") try: - os.write(tmp_fd, ifc_bytes) - os.close(tmp_fd) - return ifcopenshell.open(tmp_path) + return ifcopenshell.file.from_string(ifc_bytes.decode()) except Exception as exc: raise HTTPException(status_code=422, detail=f"Could not parse IFC file: {exc}") from exc - finally: - try: - os.unlink(tmp_path) - except OSError: - pass # ---------------------------------------------------------------------------