Skip to content

Commit 8b7aaa6

Browse files
committed
fix: One more test
1 parent 9f3d69b commit 8b7aaa6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/c2pa/c2pa.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,10 @@ class C2paSigningAlg(enum.IntEnum):
152152

153153
def _guess_mime_type_using_magic_number(file_path: Union[str, Path]) -> Optional[tuple[str, str]]:
154154
"""Guess MIME type by reading file header bytes.
155-
Currently supports:
156-
- SVG files (start with <?xml or <svg)
157-
- Image formats: PNG, JPEG, GIF, TIFF, WebP, AVIF, HEIC, HEIF, DNG
158-
- Video formats: MP4, MOV, AVI
159-
- Audio formats: MP3, M4A, WAV
160-
- Document formats: PDF
155+
Currently supports a limited set of files, as this is best effort.
156+
You should consider adding extensions to filepaths to ensure we don't
157+
have to guess too much.
158+
161159
Args:
162160
file_path: Path to the file to check
163161
Returns:
@@ -194,6 +192,8 @@ def _guess_mime_type_using_magic_number(file_path: Union[str, Path]) -> Optional
194192
return ('webp', 'image/webp')
195193
elif header.startswith(b'\x00\x00\x00\x20ftypavif'):
196194
return ('avif', 'image/avif')
195+
elif header.startswith(b'\x00\x00\x00\x18ftypmif1') or header.startswith(b'\x00\x00\x00\x18ftypmsf1') or header.startswith(b'\x00\x00\x00\x18ftypheic') or header.startswith(b'\x00\x00\x00\x18ftypheix'):
196+
return ('heic', 'image/heic')
197197

198198
# Check for audio formats
199199
elif header.startswith(b'ID3') or header.startswith(b'\xff\xfb') or header.startswith(b'\xff\xf3'):
File renamed without changes.

tests/test_unit_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ def test_guess_mime_type_using_magic_number(self):
14681468
(os.path.join(extensionless_dir, "png"), ('png', 'image/png')),
14691469
(os.path.join(extensionless_dir, "jpg"), ('jpg', 'image/jpeg')),
14701470
(os.path.join(extensionless_dir, "gif"), ('gif', 'image/gif')),
1471+
(os.path.join(extensionless_dir, "heic"), ('heic', 'image/heic')),
14711472
(os.path.join(extensionless_dir, "tiff"), ('tiff', 'image/tiff')),
14721473
(os.path.join(extensionless_dir, "webp"), ('webp', 'image/webp')),
14731474
(os.path.join(extensionless_dir, "avif"), ('avif', 'image/avif')),

0 commit comments

Comments
 (0)