Commit 4d626ab1 authored by WeidenthalerMatthias's avatar WeidenthalerMatthias
Browse files

Merge pull request !10 from WeidenthalerMatthias/feature.isfile

parents ffdd0a96 3bdf00d1
......@@ -62,6 +62,15 @@ with s3_fs.open('s3://csst-prod/gaia/test/requirements.txt', s3_options=s3_optio
file.write("CSST")
```
### Check if the given file path exists
```python
from csst_fs import fs
# local or on s3, depending on the given path
fs.isfile('requirements.txt')
fs.isfile('s3://csst-prod/test.txt')
fs.isfile('s3://csst-prod/test.txt', s3_options=s3_options)
```
## astropy直接读写s3的写法适配
### fits.open
#### 老写法
......
......@@ -2,4 +2,5 @@ from .fits import fsspec_fits
from .fits import fsspec_header
from .fits import fsspec_HDUList
from .table import fsspec_table
from . import s3_fs
\ No newline at end of file
from . import s3_fs
from . import fs
\ No newline at end of file
from .s3_fs import is_s3_path
from .s3_fs import isfile as s3_isfile
from .local_fs import isfile as local_isfile
def isfile(path: str, *args, **kwargs) -> bool:
if is_s3_path(path):
return s3_isfile(path, *args, **kwargs)
else:
return local_isfile(path, *args, **kwargs)
import os
def isfile(path: str) -> bool:
return os.path.isfile(path)
\ No newline at end of file
......@@ -15,4 +15,13 @@ def info(path, bucket=None, key=None, refresh=False, version_id=None, s3_options
return s3_fs.info(path, bucket, key, refresh, version_id)
def open(file: str, mode: str='r', s3_options=load_s3_options()):
return open_fileobj(path=file, s3_options=s3_options, mode=mode)
\ No newline at end of file
return open_fileobj(path=file, s3_options=s3_options, mode=mode)
def isfile(path: str, s3_options: dict=load_s3_options()) -> bool:
s3_fs = fsspec.filesystem('s3', **s3_options)
return s3_fs.isfile(path)
def is_s3_path(path: str):
if(path.startswith("s3")):
return True
return False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment