decalage2/olefile

bug with file object

decalage2 opened this issue · 1 comments

Originally reported by: Philippe Lagadec (Bitbucket: decalage, GitHub: decalage2)


reported on http://www.decalage.info/en/python/olefileio#comment-481

I passed a file() to OleFileIO() and got an error in this line 979:
filesize = os.path.getsize(filename)
but in line 847 you check for a file object
if hasattr(filename, 'read'):

Potential solutions:

  • use name method of file object before calling getsize (only works with real files)
  • use seek(os.SEEK_END) then tell (only works with seekable file objects)
  • do not allow file-like objects
  • read all data then check len

I think the seek/tell solution is the most appropriate, since other parts of the code require seekable file objects anyway. Non-seekable file objects could be read into memory and converted to a StringIO beforehand.


Original comment by Philippe Lagadec (Bitbucket: decalage, GitHub: decalage2):


support file-like object

fix #8