-
Notifications
You must be signed in to change notification settings - Fork 54
Description
The Problem:
If I use a ByteIO buffer to serve fabio at TIF file (i.e. "marccd/tif"), then the fabio.openimage._openimage function uses actual_filename as the buffer, and the original buffer as filename when serving to do_magic (which uses the header bytes of the file to decypher the filetype).
do_magic then fails at a filename.split call, which assumes that filename is only a string.
The use case:
I have files I want to serve and then process over a web server - I'd rather not be required to save them into local storage before pipelining the file stream into fabio.
Possible solutions:
-
Add another optional argument in
_openimagefor a buffer, then filename can be used if a buffer is provided for a string name. Ideally we modifyopenimageto be able to handle buffers too. -
Looks to me like all the python interfaces for buffers have a
nameattribute. However this looks pretty precarious and I don't believe is documented on the io documentation, but this could be used i.e.:if hasattr(filename, "seek") and hasattr(filename, "read"): # Data stream without filename filename.seek(0) data = filename.read() actual_filename = BytesIO(data) if hasattr(filename, name) and filename.name: filename = filename.name # Back to the location before the read filename.seek(0) -
(easiest?) Modify the logic in
do_magicwhen consideringelif format_type == "marccd/tif":, to not assume filename is string.
I'm happy to have a go at contributing if you don't mind and think any fix is worthwhile - keen to contribute more to open source scientific projects! :)