Skip to content

ACPFile

Base classes

Name Children Inherits
AbstractBufferedFile
fsspec.spec
Convenient class to derive from to provide buffering

⋔ Inheritance diagram

graph TD
  95970865958720["filesystem.ACPFile"]
  95970839543776["spec.AbstractBufferedFile"]
  95970836071696["io.IOBase"]
  95970835845632["_io._IOBase"]
  125067848591872["builtins.object"]
  95970839543776 --> 95970865958720
  95970836071696 --> 95970839543776
  95970835845632 --> 95970836071696
  125067848591872 --> 95970835845632

🛈 DocStrings

Bases: AbstractBufferedFile

File-like object for ACP filesystem operations.

Source code in src/aclientp/filesystem.py
class ACPFile(AbstractBufferedFile):  # type: ignore[misc]
    """File-like object for ACP filesystem operations."""

    def __init__(self, fs: ACPFileSystem, path: str, mode: str = "rb", **kwargs: Any) -> None:
        """Initialize ACP file handle."""
        super().__init__(fs, path, mode, **kwargs)
        self._content: bytes | None = None
        self.forced = False
        self.fs = fs  # assign again here just for typing

    def _fetch_range(self, start: int | None, end: int | None) -> bytes:
        """Fetch byte range from file (sync wrapper)."""
        if self._content is None:
            # Run the async operation in the event loop
            self._content = self.fs.cat_file(self.path)
            assert self._content

        if start is None and end is None:
            return self._content
        return self._content[start:end]

    def _upload_chunk(self, final: bool = False) -> bool:
        """Upload buffered data to file (sync wrapper)."""
        if final and self.buffer:
            content = self.buffer.getvalue()
            if isinstance(content, bytes):
                content = content.decode("utf-8")
            # Run the async operation in the event loop
            self.fs.put_file(self.path, content)
        return True

__init__

__init__(fs: ACPFileSystem, path: str, mode: str = 'rb', **kwargs: Any) -> None

Initialize ACP file handle.

Source code in src/aclientp/filesystem.py
def __init__(self, fs: ACPFileSystem, path: str, mode: str = "rb", **kwargs: Any) -> None:
    """Initialize ACP file handle."""
    super().__init__(fs, path, mode, **kwargs)
    self._content: bytes | None = None
    self.forced = False
    self.fs = fs  # assign again here just for typing

:fa-brands-github: Show source on GitHub