Skip to content

Commit 244dfed

Browse files
committed
Add WAV and AVI types to the file sniffer
1 parent 4854b97 commit 244dfed

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

file/sniffer.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
* Copyright(c) 2020 Google Inc.
88
*/
99

10-
// There are basically two major "container" families for modern audio-visual formats:
11-
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, etc)
12-
// 2) the Matroska family (MKV, WebM, WebP)
10+
// A Container Format is a file that embeds multiple data streams into a single file.
11+
// Relevant examples:
12+
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, MOV/QT, etc)
13+
// 2) the Matroska family (MKV, WebM)
14+
// 3) the RIFF family (WAV, AVI, WebP)
15+
// 4) the OGG family (OGV, OPUS)
16+
// 5) the ZIP family (ZIP, JAR, CBZ, EPUB, ODF, OOXML)
1317

1418
// The ISO-BMFF container needs special processing because of its "compatible brands" array :(
1519
// The Matroska container needs special processing because the sub-type can appear anywhere :(
20+
// The OGG container needs special processing to determine what kind of streams are present :(
21+
// The ZIP container needs special processing to determine what files are present inside it :(
1622

1723
// NOTE: Because the ICO format also starts with a couple zero bytes, this tree will rely on the
1824
// File Type box never going beyond 255 bytes in length which, seems unlikely according to
@@ -58,6 +64,8 @@ const fileSignatures = {
5864
[0xFF, 0xF2],
5965
[0x49, 0x44, 0x33], // 'ID3'
6066
],
67+
'audio/wav': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x41, 0x56, 0x45]], // 'RIFF....WAVE'
68+
'video/avi': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x41, 0x56, 0x49, 0x20]], // 'RIFF....AVI '
6169
};
6270

6371
// TODO: Eventually add support for various container formats so that:

tests/file-sniffer.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ describe('bitjs.file.sniffer', () => {
3838
it('TAR_1', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30]); });
3939
it('TAR_2', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00]); });
4040
it('FLAC', () => { sniffTest('audio/flac', [0x66, 0x4C, 0x61, 0x43]); });
41+
it('WAV', () => { sniffTest('audio/wav', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x57, 0x41, 0x56, 0x45, 0x81]); });
42+
it('AVI', () => { sniffTest('video/avi', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x41, 0x56, 0x49, 0x20, 0x81]); });
4143
});

0 commit comments

Comments
 (0)