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 magic numbers for WebP #54

Merged
merged 3 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0
rodineijf marked this conversation as resolved.
Show resolved Hide resolved

* Add image/webp mimeType lookup by header bytes.

# 1.0.0

* Stable null safety release.
Expand Down
33 changes: 33 additions & 0 deletions lib/src/magic_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,37 @@ const List<MagicNumber> initialMagicNumbers = [
0xFF
]),
MagicNumber('model/gltf-binary', [0x46, 0x54, 0x6C, 0x67]),

/// 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
/// -> 4 bytes have the ASCII characters 'W' 'E' 'B' 'P'.
/// https://developers.google.com/speed/webp/docs/riff_container
rodineijf marked this conversation as resolved.
Show resolved Hide resolved
MagicNumber('image/webp', [
0x52,
0x49,
0x46,
0x46,
0x00,
0x00,
0x00,
0x00,
0x57,
0x45,
0x42,
0x50
], mask: [
0xFF,
0xFF,
0xFF,
0xFF,
0x00,
0x00,
0x00,
0x00,
0xFF,
0xFF,
0xFF,
0xFF
])
];
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: mime
version: 1.0.0
version: 1.1.0

description: >-
Utilities for handling media (MIME) types, including determining a type from
Expand Down
15 changes: 15 additions & 0 deletions test/mime_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void main() {
_expectMimeType('file.pdf', 'application/pdf');
_expectMimeType('file.tiff', 'image/tiff');
_expectMimeType('file.tif', 'image/tiff');
_expectMimeType('file.webp', 'image/webp');
});

test('unknown-mime-type', () {
Expand Down Expand Up @@ -87,6 +88,20 @@ void main() {
0x70,
0x35
]);
_expectMimeType('file', 'image/webp', headerBytes: [
0x52,
0x49,
0x46,
0x46,
0xE2,
0x4A,
0x01,
0x00,
0x57,
0x45,
0x42,
0x50
]);
});
});

Expand Down