iustin / pyxattr

A python module for accessing filesystem Extended Attributes
https://pyxattr.k1024.org/
GNU Lesser General Public License v2.1
31 stars 14 forks source link

Support file-like objects #10

Closed petri closed 8 years ago

petri commented 8 years ago

Currently, passing a file-like object is not really supported.

It would be very useful to be able to pass in the file as a StringIO object. Or the equivalent Python3 equivalent.

iustin commented 8 years ago

Thanks for the bug report, but I don't understand, how would this be useful? Extended attributes are about filesystem metadata, whereas StringIO (or file like objects in general) are about data only, usually in-memory data.

petri commented 8 years ago

I need to parse the extended attributes of a file uploaded to a WWW server (uploaded using a browser).

Besides that, it is not unusual in app development that the file has been read elsewhere in the application (or by a third-party library) and only then it is possible (or most convenient) to do something with the extended attributes. Without access to the original file object or file path.

iustin commented 8 years ago

This won't work as described. Basically StringIO is just a data array, the code which reads the file would need to read the metadata and ship it along with the data. You can't retrieve the xattrs by yourself without cooperation from the original reader.

petri commented 8 years ago

Ok. I read somewhere that they are encoded within the file so I thought they would be "shipped" along just fine. It did not occur to me they could (and probably would have to) be stored "out-of-band" (even if stored with the file).

iustin commented 8 years ago

They can be encoded within the file from the filesystem point of view (I think this is the case on Windows and Mac, but not sure as I'm not familiar with those), as attribute streams; but Python regards files as a single stream of data, and metadata is separate.