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.
Asked
Active
Viewed 37 times
2 Answers
1
Not as such, however the TarFS constructor accepts an open file. So something along these lines should work:
with open_fs("ftp://user:password@host:port/") as ftp_fs:
with ftp_fs.open("path/file.tar.gz") as tar_file:
my_tar = TarFS(tar_file)
my_tar.tree()

Will McGugan
- 2,005
- 13
- 10
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_

Anton Daneyko
- 6,528
- 5
- 31
- 59