How to use the fsspec.implementations.memory.MemoryFile function in fsspec

To help you get started, we’ve selected a few fsspec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github intake / filesystem_spec / fsspec / implementations / memory.py View on Github external
identifier
        mode: str
            normally "rb", "wb" or "ab"
        """
        if mode in ["rb", "ab", "rb+"]:
            if path in self.store:
                f = self.store[path]
                if mode == "rb":
                    f.seek(0)
                else:
                    f.seek(0, 2)
                return f
            else:
                raise FileNotFoundError(path)
        if mode == "wb":
            m = MemoryFile(self, path)
            if not self._intrans:
                m.commit()
            return m
github intake / filesystem_spec / fsspec / implementations / memory.py View on Github external
**kwargs
    ):
        if mode in ["rb", "ab", "rb+"]:
            if path in self.store:
                f = self.store[path]
                if mode == "ab":
                    # position at the end of file
                    f.seek(0, 2)
                else:
                    # position at the beginning of file
                    f.seek(0)
                return f
            else:
                raise FileNotFoundError(path)
        if mode == "wb":
            m = MemoryFile(self, path)
            if not self._intrans:
                m.commit()
            return m
github intake / filesystem_spec / fsspec / implementations / memory.py View on Github external
def copy(self, path1, path2, **kwargs):
        self.store[path2] = MemoryFile(self, path2, self.store[path1].getbuffer())
github intake / filesystem_spec / fsspec / implementations / git.py View on Github external
def _open(
        self,
        path,
        mode="rb",
        block_size=None,
        autocommit=True,
        cache_options=None,
        ref=None,
        **kwargs
    ):
        obj = self._path_to_object(path, ref or self.ref)
        return MemoryFile(data=obj.data)
github intake / filesystem_spec / fsspec / implementations / github.py View on Github external
block_size=None,
        autocommit=True,
        cache_options=None,
        sha=None,
        **kwargs
    ):
        if mode != "rb":
            raise NotImplementedError
        url = self.rurl.format(
            org=self.org, repo=self.repo, path=path, sha=sha or self.root
        )
        r = requests.get(url)
        if r.status_code == 404:
            raise FileNotFoundError(path)
        r.raise_for_status()
        return MemoryFile(None, None, r.content)
github intake / filesystem_spec / fsspec / implementations / memory.py View on Github external
def cp_file(self, path1, path2, **kwargs):
        if self.isfile(path1):
            self.store[path2] = MemoryFile(self, path2, self.store[path1].getbuffer())
        elif self.isdir(path1):
            if path2 not in self.pseudo_dirs:
                self.pseudo_dirs.append(path2)
        else:
            raise FileNotFoundError