histrio/py-couchdb

enhance get_attachment

dedalus2000 opened this issue · 4 comments

I use very big attachments (50mb? 100Mb?..)

Can I suggest to stream the get_attachment result?

def get_attachment(self, doc, filename, stream=False):
..
r = self.resource(doc['_id']).get(filename, stream=stream)
..
if stream is True:
return r
return r.content

Not tested

Implemented with stream response proxy as return value.

Thanks for the idea.

Thank for your job! I've been thinking to a requests-couchdb module for months..

About the last update, I see you kept the "stream=False" in the client.py#485

r = self.resource(doc['_id']).get(filename, stream=False)
if stream:
....return _StreamResponse(r)

So, does _StreamResponse(r) get an entire not-streamed attachment? In this case it does not avoid to keep the entire attachment in memory (it simple serves a streamed content, but it read it completely in one time)
Should it be better "stream=True" ?

I didn't look at the "resource" module, so I can't be sure about it; neither I did some tests.
I only exposed my doubt

My two cents.

Is my mistake. Now fixed in the last commit.