Skip to content

Commit

Permalink
readme and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanis Benson committed May 4, 2019
1 parent 5a50e54 commit 5d79985
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 5 additions & 5 deletions index.js
Expand Up @@ -280,15 +280,15 @@ const fileType = input => {
}

// File Type Box (https://en.wikipedia.org/wiki/ISO_base_media_file_format)
// It is not required to be first, but is recommended to, almost all mpeg4 files start with ftyp box
// `ftyp` box must contain brand identifier, which must consist of ISO 8859-1 printable characters
// Here we check for 8859-1 printable characters + 1 unprintable for check simplicity
// They all can have mime video/mp4 except application/mp4 special case which is hard to detect.
// For some cases we're specific, everything else falls to video/mp4 with mp4 extension.
// It is not required to be first, but is recommended to, almost all ISO base media files start with ftyp box
// `ftyp` box must contain brand major identifier, which must consist of ISO 8859-1 printable characters
// Here we check for 8859-1 printable characters(for check simplicity, it is a mask which also catches one non-printable character).
if (
check([0x66, 0x74, 0x79, 0x70], {offset: 4}) && // `ftyp`
(buf[8] & 0x60) !== 0x00 && (buf[9] & 0x60) !== 0x00 && (buf[10] & 0x60) !== 0x00 && (buf[11] & 0x60) !== 0x00 // Brand major
) {
// They all can have mime video/mp4 except application/mp4 special case which is hard to detect.
// For some cases we're specific, everything else falls to video/mp4 with mp4 extension.
const brandMajor = buf.toString('utf8', 8, 12);
switch (brandMajor) {
case 'mif1':
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Expand Up @@ -142,7 +142,6 @@ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream
- [`7z`](https://en.wikipedia.org/wiki/7z)
- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image)
- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions)
- [`m4v`](https://en.wikipedia.org/wiki/M4V)
- [`mid`](https://en.wikipedia.org/wiki/MIDI)
- [`mkv`](https://en.wikipedia.org/wiki/Matroska)
- [`webm`](https://en.wikipedia.org/wiki/WebM)
Expand Down Expand Up @@ -222,6 +221,15 @@ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream
- [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias file
- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File
- [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - ATSC A/52 Audio File
- [`3g2`](https://en.wikipedia.org/wiki/3GP_and_3G2#3G2) - Multimedia container format defined by the 3GPP2 for 3G CDMA2000 multimedia services
- [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files
- [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks
- [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store
- [`m4v`](https://en.wikipedia.org/wiki/M4V) - MPEG-4 Visual bitstreams
- [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Audio-only ISO base media file format used by Adobe Flash Player
- [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Audiobook and podcast ISO base media file format used by Adobe Flash Player
- [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format protected by Adobe Access DRM used by Adobe Flash Player
- [`f4v`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format used by Adobe Flash Player

*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*

Expand Down

0 comments on commit 5d79985

Please sign in to comment.