in iopath/common/s3.py [0:0]
def _ls(self, path: str, **kwargs: Any) -> List[str]:
"""
List the contents of the directory at the provided URI.
Args:
path (str): A URI supported by this PathHandler
Returns:
List[str]: list of contents in given path
"""
self._check_kwargs(kwargs)
bucket, s3_path = self._parse_uri(path)
client = self._get_client(bucket)
try:
# Pagination needed if >1000 entries.
paginator = client.get_paginator("list_objects_v2")
pages = paginator.paginate(
Bucket=bucket,
Prefix=s3_path,
Delimiter="/",
)
obj_results = [
obj["Key"] for page in pages for obj in page.get("Contents", [])
]
dir_results = [
obj["Prefix"]
for page in pages
for obj in page.get("CommonPrefixes", [])
]
return obj_results + dir_results
except botocore.exceptions.ClientError as e:
raise OSError(
f"Error in ls path {path} - " f"{type(e).__name__}: {e}"
) from e