take read handle as argument instead of file path

This commit is contained in:
Kay Kurokawa 2017-10-02 18:07:07 -04:00
parent d68ca65e41
commit e07c2f7bd8
2 changed files with 5 additions and 5 deletions

View file

@ -78,7 +78,8 @@ class BlobFile(object):
finished finished
""" """
if self._verified is True: if self._verified is True:
reader = HashBlobReader(self.file_path, self.reader_finished) f = open(self.file_path, 'rb')
reader = HashBlobReader(f, self.reader_finished)
self.readers += 1 self.readers += 1
return reader return reader
return None return None

View file

@ -39,16 +39,15 @@ class HashBlobReader(object):
This is a file like reader class that supports This is a file like reader class that supports
read(size) and close() read(size) and close()
""" """
def __init__(self, file_path, finished_cb): def __init__(self, read_handle, finished_cb):
self.file_path = file_path
self.finished_cb = finished_cb self.finished_cb = finished_cb
self.finished_cb_d = None self.finished_cb_d = None
self.read_handle = open(self.file_path, 'rb') self.read_handle = read_handle
def __del__(self): def __del__(self):
if self.finished_cb_d is None: if self.finished_cb_d is None:
log.warn("Garbage collection was called, but reader for %s was not closed yet", log.warn("Garbage collection was called, but reader for %s was not closed yet",
self.file_path) self.read_handle.name)
self.close() self.close()
def read(self, size=-1): def read(self, size=-1):