Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh.from_file from BytesIO / SpooledTemporaryFile #146

Closed
mrtnbrst opened this issue Oct 10, 2020 · 3 comments
Closed

Mesh.from_file from BytesIO / SpooledTemporaryFile #146

mrtnbrst opened this issue Oct 10, 2020 · 3 comments

Comments

@mrtnbrst
Copy link

Is it possible to use an in memory object like BytesIO to load a numpy-stl mesh?

Right now there seems to be an issue with the use of numpy.fromfile in https://github.com/WoLpH/numpy-stl/blob/92900a54dd4446bacc827fb11b958e8ea6416c56/stl/stl.py#L128.
This numpy/numpy#2230 addresses this behaviour and potential workarounds like numpy.frombuffer .

import base64
import io
import tempfile

with open(r"C:\Users\user\Moon.stl", "rb") as f:
    decoded = base64.b64decode(f.read())
    
data = data = io.BytesIO(decoded)

mesh.Mesh.from_file("Moon.stl", fh=data)

"""
mesh.Mesh.from_file("test", fh=data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\miniconda3\envs\streamlit\lib\site-packages\stl\stl.py", line 326, in from_file
    fh, mode=mode, speedups=speedups)
  File "C:\Users\user\miniconda3\envs\streamlit\lib\site-packages\stl\stl.py", line 95, in load
    name, data = cls._load_binary(fh, header)
  File "C:\Users\user\miniconda3\envs\streamlit\lib\site-packages\stl\stl.py", line 128, in _load_binary
    return name, numpy.fromfile(fh, dtype=cls.dtype, count=count)
io.UnsupportedOperation: fileno
"""

fh = tempfile.SpooledTemporaryFile(decoded)
mesh.Mesh.from_file("Moon.stl", fh=fh)

"""
mesh.Mesh.from_file("Moon.stl", fh=fh)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user\miniconda3\envs\streamlit\lib\site-packages\stl\stl.py", line 326, in from_file
    fh, mode=mode, speedups=speedups)
TypeError: cannot unpack non-iterable NoneType object
>>>
"""

System: Windows 10, 10.0.17134 Build 17134

@wolph wolph closed this as completed in be92a92 Oct 11, 2020
@wolph
Copy link
Owner

wolph commented Oct 11, 2020

Wow... crazy that an issue since 2012 still hasn't been fixed :P

In any case, it's easy enough to fix so a new release will be coming soon. The new version is on develop

@mrtnbrst
Copy link
Author

Thank you!

@wolph
Copy link
Owner

wolph commented Oct 11, 2020

The new release is online :)

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 12, 2020
  fixed #146. worked around numpy bug when reading from BytesIO
  See wolph/numpy-stl#146

Reported by:	portscout


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@552148 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 12, 2020
  fixed #146. worked around numpy bug when reading from BytesIO
  See wolph/numpy-stl#146

Reported by:	portscout
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this issue Oct 12, 2020
  fixed #146. worked around numpy bug when reading from BytesIO
  See wolph/numpy-stl#146

Reported by:	portscout


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@552148 35697150-7ecd-e111-bb59-0022644237b5
hardenedbsd-services pushed a commit to HardenedBSD/hardenedbsd-ports that referenced this issue Oct 12, 2020
* freebsd/master:
  update firefox to 81.0.2
  Update to 1.24.0
  net-im/telegram-desktop: Respect user font settings
  graphics/mesa-devel: pin to llvm10 like mesa-dri
  - Update to 2.11.3   fixed #146. worked around numpy bug when reading from BytesIO   See wolph/numpy-stl#146
  www/radicale: Redirect logging to syslog since radicale 3 is now logging to stderr per default
  databases/pg_repack: Update to 1.4.6
  devel/ncurses: update to 20201010 snapshot
  dns/dnscontrol: Update to 3.4.2
  devel/intel-graphics-compiler: update to 1.0.5186
  devel/py-sysctl: fix build on GCC architectures
  Add libunwind for aarch64, powerpc64 and powerpc64le.
  Fix depends
  Fix COMMENT for default FLAVOR
  Update to the 20201009 snapshot of GCC 9.3.1.
svmhdvn pushed a commit to svmhdvn/freebsd-ports that referenced this issue Jan 10, 2024
  fixed #146. worked around numpy bug when reading from BytesIO
  See wolph/numpy-stl#146

Reported by:	portscout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants