Ejemplo n.º 1
0
    async def fd_read(self,
                      fd: FileDescriptor,
                      size: int,
                      offset: int,
                      raise_eof: bool = False) -> bytes:
        # Loop over attemps
        missing: List[BlockAccess] = []
        while True:

            # Load missing blocks
            await self.remote_loader.load_blocks(missing)

            # Fetch and lock
            async with self._load_and_lock_file(fd) as manifest:

                # End of file
                if raise_eof and offset >= manifest.size:
                    raise FSEndOfFileError()

                # Normalize
                offset = normalize_argument(offset, manifest)
                size = normalize_argument(size, manifest)

                # No-op
                if offset > manifest.size:
                    return b""

                # Prepare
                chunks = prepare_read(manifest, size, offset)
                data, missing = await self._build_data(chunks)

                # Return the data
                if not missing:
                    return data
Ejemplo n.º 2
0
 def read(self, manifest: LocalFileManifest, size: int,
          offset: int) -> bytearray:
     chunks = prepare_read(manifest, size, offset)
     return self.build_data(chunks)