|
3 | 3 | from typing import Union, List, Optional, Tuple, Iterable |
4 | 4 | import fsspec |
5 | 5 |
|
6 | | -from .filesystem import FileSystem |
| 6 | +from .filesystem import FileSystem, FileData |
7 | 7 |
|
8 | 8 |
|
9 | 9 | class S3FileSystem(FileSystem): |
@@ -63,6 +63,24 @@ def listdir( |
63 | 63 | files = ["s3://" + f for f in files] |
64 | 64 | return files |
65 | 65 |
|
| 66 | + def listdir_meta(self, folder_path: str) -> List[FileData]: |
| 67 | + folder_path = folder_path.lstrip("s3://").rstrip("/") + "/" |
| 68 | + s3 = fsspec.filesystem("s3", **self.storage_options) |
| 69 | + files_data = s3.ls(folder_path, detail=True) |
| 70 | + |
| 71 | + results = [] |
| 72 | + for file_data in files_data: |
| 73 | + if file_data['Key'] == folder_path: |
| 74 | + continue |
| 75 | + path = "s3://"+file_data['Key'] |
| 76 | + filetype = file_data['type'] |
| 77 | + size = None |
| 78 | + last_modified = file_data.get('LastModified', None) |
| 79 | + if filetype == 'file': |
| 80 | + size = file_data.get('Size', None) |
| 81 | + results.append(FileData(path, filetype, last_modified, size)) |
| 82 | + return results |
| 83 | + |
66 | 84 | def mkdir(self, folder_path: str) -> None: |
67 | 85 | folder_path = folder_path.rstrip("/") + "/" |
68 | 86 | s3 = fsspec.filesystem("s3", **self.storage_options) |
|
0 commit comments