Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling for "files" that are purely in memory? #16

Open
spott opened this issue Jan 7, 2017 · 2 comments
Open

Handling for "files" that are purely in memory? #16

spott opened this issue Jan 7, 2017 · 2 comments
Labels

Comments

@spott
Copy link

spott commented Jan 7, 2017

More accurately, how am I supposed to handle a "file" that is really just a bunch of bytes?

Ideally, I would like to use a BinaryIO object, however, these don't have a name attribute, so I get this error:

  File "/usr/local/lib/python3.5/site-packages/warcat/model/block.py", line 83, in load
    binary_block.set_file(file_obj.name or file_obj, file_obj.tell(), length)
AttributeError: '_io.BytesIO' object has no attribute 'name'

I'm not sure how to get around this.

@chfoo chfoo added the bug label Jan 8, 2017
@chfoo
Copy link
Owner

chfoo commented Jan 8, 2017

Oops, another case that wasn't tested. As a workaround, maybe try something like your_file_object.name = None?

@spott
Copy link
Author

spott commented Jan 9, 2017

This actually isn't enough...

You use file_obj.peek() in the code, and BinaryIO objects don't have that function.

Interestingly, my workaround is to use GzipFile, which does have a peek function and takes BinaryIO objects.

If you are interested, accepting the BufferedIOBase interface (in the io library) should allow you to take most file-like objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants