I would like to use pyfilesystem with a combination of schemas. For example, I want to open a tar file on an FTP server and I would do ftp+tar://user:password@host:port/path/file.tar.gz.
Can pyfilesystem combine schemas?
53 Views Asked by Anton Daneyko At
2
There are 2 best solutions below
0

I ended up with something like this:
@contextmanager
def open_url(url: str,
mode: str = "r",
create: bool = False,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: str = "",
**options: Any,
) -> typing.IO:
writeable = True if "w" in mode else False
dir_url, file_name = os.path.split(url)
with open_fs(dir_url, writeable, create) as fs_:
with fs_.open(file_name, mode, buffering, encoding, errors, newline,
**options) as file_:
yield file_
Not as such, however the TarFS constructor accepts an open file. So something along these lines should work: