diff options
-rwxr-xr-x | fusearchive.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/fusearchive.py b/fusearchive.py index f648235..bcfed7c 100755 --- a/fusearchive.py +++ b/fusearchive.py @@ -435,21 +435,33 @@ class FuseArchive(Fuse): + " length: " + str( length ) ) data_read = 0 - data = None + data = '' index = int( offset / self.chunk_size ) rest = offset % self.chunk_size + is_eof = False # Keep reading chunks until we have at least this much data - while data_read < length: + while data_read < length and not is_eof: dmsg( 3, "Pulling chunk data" ) self._load_chunk( index ) - chunk_remaining = self.chunk_size - rest - data += substr( self.chunk[ rest:chunk_remaining ] ) - data_read = len( data ) - index += 1 - rest = 0 + if len(self.chunk): + chunk_remaining = len(self.chunk) - rest + to_read = chunk_remaining + data_left = length - data_read + if data_left < chunk_remaining: + to_read = data_left + + dmsg( 3, "Copying " + str(to_read) + " bytes" ) + + data += self.chunk[ rest:chunk_remaining ] + data_read += to_read + index += 1 + rest = 0 + else: + dmsg( 3, "No more chunk data, bye" ) + is_eof = True - return data[ :length ] + return data def write(self, buf, offset): dmsg( 3, "Writing to " + self.orig_path + " offset: " + str( offset ) ) |