athena: return current upload status in listUploadQueue (#21903)

* return current upload item in listUploadQueue

* update progress on read

* move to file helpers

* use dict instead of global
old-commit-hash: 28823917ea87edebf66f568f15f965028b0a2ff5
This commit is contained in:
Willem Melching
2021-08-13 11:51:08 +02:00
committed by GitHub
parent 48f53addbf
commit dad760624a
3 changed files with 88 additions and 21 deletions

View File

@@ -79,6 +79,25 @@ class NamedTemporaryDir():
self.close()
class CallbackReader:
"""Wraps a file, but overrides the read method to also
call a callback function with the number of bytes read so far."""
def __init__(self, f, callback, *args):
self.f = f
self.callback = callback
self.cb_args = args
self.total_read = 0
def __getattr__(self, attr):
return getattr(self.f, attr)
def read(self, *args, **kwargs):
chunk = self.f.read(*args, **kwargs)
self.total_read += len(chunk)
self.callback(*self.cb_args, self.total_read)
return chunk
def _get_fileobject_func(writer, temp_dir):
def _get_fileobject():
file_obj = writer.get_fileobject(dir=temp_dir)