Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for image/avif #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
* Update video/mp4 mimeType lookup by header bytes.
* Add image/heic mimeType lookup by header bytes.
* Add image/heif mimeType lookup by header bytes.
* Add image/avif mimeType lookup by header bytes.
* Add m4b mimeType lookup by extension.
* Add `text/markdown` mimeType lookup by extension.
* Require Dart 3.0.0.
Expand Down
32 changes: 32 additions & 0 deletions lib/src/magic_number.dart
Expand Up @@ -275,6 +275,38 @@ const List<MagicNumber> initialMagicNumbers = [
]),
MagicNumber('model/gltf-binary', [0x46, 0x54, 0x6C, 0x67]),

/// AVIF format identification
/// -> 4 bytes indicating the ftyp box length.
/// -> 4 bytes have the ASCII characters 'f' 't' 'y' 'p'.
/// -> 4 bytes have the ASCII characters 'a' 'v' 'i' 'f'.
MagicNumber('image/avif', [
0x00,
0x00,
0x00,
0x00,
0x66,
0x74,
0x79,
0x70,
0x61,
0x76,
0x69,
0x66
], mask: [
0x00,
0x00,
0x00,
0x00,
0xFF,
0xFF,
0xFF,
0xFF,
0xFF,
0xFF,
0xFF,
0xFF
]),

/// The WebP file format is based on the RIFF document format.
/// -> 4 bytes have the ASCII characters 'R' 'I' 'F' 'F'.
/// -> 4 bytes indicating the size of the file
Expand Down
14 changes: 14 additions & 0 deletions test/mime_type_test.dart
Expand Up @@ -75,6 +75,20 @@ void main() {
0x1A,
0x0A
]);
_expectMimeType('file.avif', 'image/avif', headerBytes: [
0x00,
0x00,
0x00,
0x20,
0x66,
0x74,
0x79,
0x70,
0x61,
0x76,
0x69,
0x66
]);
_expectMimeType('file.gif', 'image/jpeg', headerBytes: [
0xFF,
0xD8,
Expand Down