nschloe / meshio

:spider_web: input/output for many mesh formats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having trouble with saving file as in-memory buffer

RadheChandu opened this issue · comments

Hello meshioTeam,

Thank you for making such a great product. I am working on a project wherein I need to work on openfoam results files. I need mesh file in '.mesh' format which I am converting using meshio. But I dont want to save a physical file, rather would like to use as in-memory buffer.

I am using the following code..
`points = Zoner.points
cells = [("hexahedron", [Zoner.cell_point_ids(i)])
for i in range(Zoner.n_cells)]

mesh = meshio.Mesh(points, cells)

import io

buffer = io.BytesIO()

mesh.write(buffer, file_format = 'gmsh')`

I am getting the following error.

`Traceback (most recent call last):

Input In [88] in <cell line: 11>
mesh.write(buffer, file_format = 'gmsh')

File ~\AppData\Roaming\Python\Python39\site-packages\meshio_mesh.py:241 in write
write(path_or_buf, self, file_format, **kwargs)

File ~\AppData\Roaming\Python\Python39\site-packages\meshio_helpers.py:188 in write
return writer(filename, mesh, **kwargs)

File ~\AppData\Roaming\Python\Python39\site-packages\meshio\gmsh\main.py:111 in
"gmsh": lambda f, m, **kwargs: write(f, m, "4.1", **kwargs),

File ~\AppData\Roaming\Python\Python39\site-packages\meshio\gmsh\main.py:102 in write
writer.write(filename, mesh, binary=binary, float_fmt=float_fmt)

File ~\AppData\Roaming\Python\Python39\site-packages\meshio\gmsh_gmsh41.py:313 in write
with open(filename, "wb") as fh:

TypeError: expected str, bytes or os.PathLike object, not BytesIO`

Can you please help me with this..