Example #1
0
 def open_file(self, name, *args, **kwargs):
     offset, length = self.range(name)
     if self._source:
         # Create a memoryview/buffer from the mmap
         buf = memoryview_(self._source, offset, length)
         f = BufferFile(buf, name=name)
     elif hasattr(self._file, "subset"):
         f = self._file.subset(offset, length, name=name)
     else:
         f = StructFile(SubFile(self._file, offset, length), name=name)
     return f
 def _open_encrypted_file(self, name, onclose=lambda x: None):
     if not self.file_exists(name):
         if name in self._open_files:
             f = self._open_files[name]
             if not f.is_closed:
                 state = 'closed' if f.file.shouldClose else 'open'
                 if state == 'closed':
                     self._store_file(name, f.file.getvalue())
                     f.close()
                     del self._open_files[name]
         else:
             raise NameError(name)
     file_content = open(self._fpath(name), "rb").read()
     decrypted = self.decrypt(file_content)
     self.length_cache[name] = (len(decrypted), sha256(decrypted).digest())
     return BufferFile(buffer(decrypted), name=name, onclose=onclose)
Example #3
0
 def open_file(self, name, **kwargs):
     if name not in self.files:
         raise NameError(name)
     buf = memoryview_(self.files[name])
     return BufferFile(buf, name=name, **kwargs)
 def _open_encrypted_file(self, name, onclose=lambda x: None):
     file_content = open(self._fpath(name), "rb").read()
     decrypted = self.f.decrypt(file_content)
     self.length_cache[name] = len(decrypted)
     return BufferFile(buffer(decrypted), name=name, onclose=onclose)