path_utils.py 538 B

1234567891011121314151617181920212223
  1. from s3pathlib import S3Path
  2. def remove_non_official_s3_args(s3path):
  3. """
  4. example: s3://abc/xxxx.json?bytes=0,81350 ==> s3://abc/xxxx.json
  5. """
  6. arr = s3path.split("?")
  7. return arr[0]
  8. def parse_s3path(s3path: str):
  9. p = S3Path(remove_non_official_s3_args(s3path))
  10. return p.bucket, p.key
  11. def parse_s3_range_params(s3path: str):
  12. """
  13. example: s3://abc/xxxx.json?bytes=0,81350 ==> [0, 81350]
  14. """
  15. arr = s3path.split("?bytes=")
  16. if len(arr) == 1:
  17. return None
  18. return arr[1].split(",")