Merge pull request #526 from bongbui321/fix_sparse

Better performance for sparse image flashing
This commit is contained in:
Bjoern Kerler 2024-03-29 10:25:35 +01:00 committed by GitHub
commit ab98fec4e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,9 @@ sys.path.insert(0, parent_dir)
from edlclient.Library.utils import LogBase, print_progress
MAX_STORE_SIZE = 1024 * 1024 * 1024 * 2 # 2 GBs
class QCSparse(metaclass=LogBase):
def __init__(self, filename, loglevel):
self.rf = open(filename, 'rb')
@ -36,6 +39,8 @@ class QCSparse(metaclass=LogBase):
self.total_chunks = None
self.image_checksum = None
self.tmp_offset = 0
self.info = self.__logger.info
self.debug = self.__logger.debug
self.error = self.__logger.error
@ -172,17 +177,20 @@ class QCSparse(metaclass=LogBase):
return length
def read(self, length=None):
if self.tmp_offset >= MAX_STORE_SIZE:
self.tmpdata = self.tmpdata[self.tmp_offset:]
self.tmp_offset = 0
if length is None:
return self.unsparse()
if length <= len(self.tmpdata):
tdata = self.tmpdata[:length]
self.tmpdata = self.tmpdata[length:]
if (self.tmp_offset + length) <= len(self.tmpdata):
tdata = self.tmpdata[self.tmp_offset : self.tmp_offset + length]
self.tmp_offset += length
return tdata
while len(self.tmpdata) < length:
while (self.tmp_offset + length) > len(self.tmpdata):
self.tmpdata.extend(self.unsparse())
if length <= len(self.tmpdata):
tdata = self.tmpdata[:length]
self.tmpdata = self.tmpdata[length:]
if (self.tmp_offset + length) <= len(self.tmpdata):
tdata = self.tmpdata[self.tmp_offset : self.tmp_offset + length]
self.tmp_offset += length
return tdata