Skip to content

Commit 8920154

Browse files
committed
file-mode-api: provide ability to source to provide a path extractor using uri as argument
1 parent 199d99a commit 8920154

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

airbyte_cdk/sources/file_based/file_based_stream_reader.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from enum import Enum
99
from io import IOBase
1010
from os import makedirs, path
11-
from typing import Any, Iterable, List, Optional, Set, Tuple, MutableMapping
11+
from typing import Any, Callable, Iterable, List, Optional, Set, Tuple, MutableMapping
1212

1313
from wcmatch.glob import GLOBSTAR, globmatch
1414

@@ -176,14 +176,18 @@ def upload(
176176
"""
177177
...
178178

179-
def _get_file_transfer_paths(self, file: RemoteFile, local_directory: str) -> MutableMapping[str, Any]:
179+
def _get_file_transfer_paths(self, file: RemoteFile, local_directory: str, parse_file_path_from_uri: Optional[Callable] = None) -> MutableMapping[str, Any]:
180180
preserve_directory_structure = self.preserve_directory_structure()
181-
file_uri = file.uri
182-
file_name = path.basename(file_uri)
183-
file_folder = path.dirname(file_uri)
181+
if not parse_file_path_from_uri:
182+
file_path = file.uri
183+
else:
184+
file_path = parse_file_path_from_uri(file.uri)
185+
186+
file_name = path.basename(file_path)
187+
file_folder = path.dirname(file_path)
184188
if preserve_directory_structure:
185189
# Remove left slashes from source path format to make relative path for writing locally
186-
file_relative_path = file_uri.lstrip("/")
190+
file_relative_path = file_path.lstrip("/")
187191
else:
188192
file_relative_path = file_name
189193
local_file_path = path.join(local_directory, file_relative_path)
@@ -195,7 +199,7 @@ def _get_file_transfer_paths(self, file: RemoteFile, local_directory: str) -> Mu
195199
self.LOCAL_FILE_PATH: local_file_path,
196200
self.FILE_NAME: file_name,
197201
self.FILE_FOLDER: file_folder,
198-
self.SOURCE_FILE_URI: file_uri,
202+
self.SOURCE_FILE_URI: file.uri,
199203

200204
}
201205
return file_paths

0 commit comments

Comments
 (0)