Add magic numbers for AIFF, WAVE and FLAC files (#53)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 52c625f..3a3eb5d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 1.0.2
+
+* Add audio/x-aiff mimeType lookup by header bytes.
+* Add audio/x-flac mimeType lookup by header bytes.
+* Add audio/x-wav mimeType lookup by header bytes.
+
# 1.0.1
* Add image/webp mimeType lookup by header bytes.
diff --git a/lib/src/magic_number.dart b/lib/src/magic_number.dart
index 78255c5..0cb5a8d 100644
--- a/lib/src/magic_number.dart
+++ b/lib/src/magic_number.dart
@@ -31,6 +31,76 @@
const List<MagicNumber> initialMagicNumbers = [
MagicNumber('application/pdf', [0x25, 0x50, 0x44, 0x46]),
MagicNumber('application/postscript', [0x25, 0x51]),
+
+ /// AIFF is based on the EA IFF 85 Standard for Interchange Format Files.
+ /// -> 4 bytes have the ASCII characters 'F' 'O' 'R' 'M'.
+ /// -> 4 bytes indicating the size of the file
+ /// -> 4 bytes have the ASCII characters 'A' 'I' 'F' 'F'.
+ /// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Docs/AIFF-1.3.pdf
+ MagicNumber('audio/x-aiff', [
+ 0x46,
+ 0x4F,
+ 0x52,
+ 0x4D,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x41,
+ 0x49,
+ 0x46,
+ 0x46
+ ], mask: [
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF
+ ]),
+
+ /// -> 4 bytes have the ASCII characters 'f' 'L' 'a' 'C'.
+ /// https://xiph.org/flac/format.html
+ MagicNumber('audio/x-flac', [0x66, 0x4C, 0x61, 0x43]),
+
+ /// The WAVE 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' 'A' 'V' 'E'.
+ /// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
+ MagicNumber('audio/x-wav', [
+ 0x52,
+ 0x49,
+ 0x46,
+ 0x46,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x57,
+ 0x41,
+ 0x56,
+ 0x45
+ ], mask: [
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF
+ ]),
MagicNumber('image/gif', [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]),
MagicNumber('image/gif', [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]),
MagicNumber('image/jpeg', [0xFF, 0xD8]),
diff --git a/pubspec.yaml b/pubspec.yaml
index 1aca7a0..f0c92f1 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: mime
-version: 1.0.1
+version: 1.0.2
description: >-
Utilities for handling media (MIME) types, including determining a type from
diff --git a/test/mime_type_test.dart b/test/mime_type_test.dart
index e02e0af..ac0db01 100644
--- a/test/mime_type_test.dart
+++ b/test/mime_type_test.dart
@@ -41,6 +41,7 @@
_expectMimeType('file.tiff', 'image/tiff');
_expectMimeType('file.tif', 'image/tiff');
_expectMimeType('file.webp', 'image/webp');
+ _expectMimeType('file.aiff', 'audio/x-aiff');
});
test('unknown-mime-type', () {
@@ -102,6 +103,36 @@
0x42,
0x50
]);
+ _expectMimeType('file', 'audio/x-aiff', headerBytes: [
+ 0x46,
+ 0x4F,
+ 0x52,
+ 0x4D,
+ 0x04,
+ 0x0B,
+ 0xEF,
+ 0xF4,
+ 0x41,
+ 0x49,
+ 0x46,
+ 0x46
+ ]);
+ _expectMimeType('file', 'audio/x-flac',
+ headerBytes: [0x66, 0x4C, 0x61, 0x43]);
+ _expectMimeType('file', 'audio/x-wav', headerBytes: [
+ 0x52,
+ 0x49,
+ 0x46,
+ 0x46,
+ 0xA6,
+ 0x4E,
+ 0x70,
+ 0x03,
+ 0x57,
+ 0x41,
+ 0x56,
+ 0x45
+ ]);
});
});