# vtk handling of python file-like objects, gzipped stls

**URL:** https://discourse.vtk.org/t/vtk-handling-of-python-file-like-objects-gzipped-stls/5350
**Category:** Support
**Created:** [March 9, 2021, 3:52pm UTC](https://discourse.vtk.org/t/vtk-handling-of-python-file-like-objects-gzipped-stls/5350 "2021-03-09T15:52:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aerogt3](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@aerogt3](https://discourse.vtk.org/u/aerogt3)
#### Post date: [March 9, 2021, 3:52pm UTC](https://discourse.vtk.org/t/vtk-handling-of-python-file-like-objects-gzipped-stls/5350/1 "2021-03-09T15:52:35Z")

</div>

Hello,

I am using python vtk for reading in, manipulating, and then exporting .stl files. Often these are gzipped, or download from/exported to a remote file system (amazon s3).

If there any way to use vtkSTLReader and vtkSTLWriter with python file-like objects? This would allow me to zip/unzip in a purely pythonic way, and obviate the need for writing temp files both in zipping and in down/uploading to s3. Or, any workaround that can skip the temp file creation?

Thanks!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 9, 2021, 4:17pm UTC](https://discourse.vtk.org/t/vtk-handling-of-python-file-like-objects-gzipped-stls/5350/2 "2021-03-09T16:17:12Z")

</div>

VTK I/O filters tend to work with file names rather than stream objects (even passing a `FILE*` or `std::istream`/`std::ostream` to the filters is a no-go). I think this is because VTK filters like to open/close files explicitly rather than relying on “I’m done writing data” signals of any kind or needing some way to “rewind” a file that it wants to read again.

So, no, there’s probably no way to avoid the temporary file creation without some more thought put into VTK’s I/O strategies in use.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 9, 2021, 4:46pm UTC](https://discourse.vtk.org/t/vtk-handling-of-python-file-like-objects-gzipped-stls/5350/3 "2021-03-09T16:46:45Z")

</div>

The vtkSTLReader checks the file size, which is a no-go for streaming (I’m not sure if it absolutely has to, but it does). And as Ben pointed out, it’s not uncommon for a reader to have to seek within the file.

I wrote the Python wrappers to be able to recognize std::istream and std::ostream parameters, but in the end I never hooked these up to Python streams because I found that the actual usefulness of this was less than I had originally thought. I’m willing to help if anyone wants to give it a go.
