Skip to content

Commit f2b959c

Browse files
fix: update detect_filetype calls to match new API
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent c84bebc commit f2b959c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

airbyte_cdk/sources/file_based/file_types/unstructured_parser.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,21 @@ def _get_filetype(self, file: IOBase, remote_file: RemoteFile) -> Optional[FileT
423423
# if the file name is not available, use the file content
424424
detected_type: FileType | None = None
425425
try:
426-
detected_type = detect_filetype(
427-
filename=remote_file.uri,
428-
)
426+
detected_type = detect_filetype(remote_file.uri)
429427
except Exception:
430428
# Path doesn't exist locally. Try something else...
431429
pass
432430

433431
if detected_type and detected_type != FileType.UNK:
434432
return detected_type
435433

436-
type_based_on_content = detect_filetype(file=file)
437-
file.seek(0) # detect_filetype is reading to read the file content, so we need to reset
434+
# Convert IOBase to BytesIO for compatibility with detect_filetype
435+
file.seek(0)
436+
file_content = file.read()
437+
file.seek(0)
438+
with BytesIO(file_content) as bytes_io:
439+
type_based_on_content = detect_filetype(bytes_io)
440+
file.seek(0) # Reset file position after reading
438441

439442
if type_based_on_content and type_based_on_content != FileType.UNK:
440443
return type_based_on_content

0 commit comments

Comments
 (0)