@@ -125,7 +125,7 @@ def get_bucket(self, name):
125125 """Get a bucket."""
126126 raise NotImplementedError
127127
128- def list_blobs (self , remote_path , recursive = True ):
128+ def list_blobs (self , remote_path , recursive = True , names_only = False ):
129129 """List the blobs under the remote path."""
130130 raise NotImplementedError
131131
@@ -228,7 +228,7 @@ def get_bucket(self, name):
228228
229229 raise
230230
231- def list_blobs (self , remote_path , recursive = True ):
231+ def list_blobs (self , remote_path , recursive = True , names_only = False ):
232232 """List the blobs under the remote path."""
233233 bucket_name , path = get_bucket_name_and_path (remote_path )
234234
@@ -244,7 +244,13 @@ def list_blobs(self, remote_path, recursive=True):
244244 else :
245245 delimiter = '/'
246246
247- iterator = bucket .list_blobs (prefix = path , delimiter = delimiter )
247+ if names_only :
248+ fields = 'items(name),nextPageToken'
249+ else :
250+ fields = None
251+
252+ iterator = bucket .list_blobs (
253+ prefix = path , delimiter = delimiter , fields = fields )
248254 for blob in iterator :
249255 properties ['bucket' ] = bucket_name
250256 properties ['name' ] = blob .name
@@ -567,8 +573,9 @@ def _list_files_nonrecursive(self, fs_path):
567573 for filename in os .listdir (fs_path ):
568574 yield os .path .join (fs_path , filename )
569575
570- def list_blobs (self , remote_path , recursive = True ):
576+ def list_blobs (self , remote_path , recursive = True , names_only = False ):
571577 """List the blobs under the remote path."""
578+ del names_only
572579 bucket , _ = get_bucket_name_and_path (remote_path )
573580 fs_path = self .convert_path (remote_path )
574581
@@ -1070,7 +1077,8 @@ def get_blobs(cloud_storage_path, recursive=True):
10701077 exception_types = _TRANSIENT_ERRORS )
10711078def list_blobs (cloud_storage_path , recursive = True ):
10721079 """Return blob names under the given cloud storage path."""
1073- for blob in _provider ().list_blobs (cloud_storage_path , recursive = recursive ):
1080+ for blob in _provider ().list_blobs (
1081+ cloud_storage_path , recursive = recursive , names_only = True ):
10741082 yield blob ['name' ]
10751083
10761084
0 commit comments