From 244dfed5d966b23254c8277d48ffdc17b0350cc9 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Thu, 16 Feb 2023 20:32:17 -0800 Subject: [PATCH] Add WAV and AVI types to the file sniffer --- file/sniffer.js | 14 +++++++++++--- tests/file-sniffer.spec.js | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/file/sniffer.js b/file/sniffer.js index 1551e67..7bea574 100644 --- a/file/sniffer.js +++ b/file/sniffer.js @@ -7,12 +7,18 @@ * Copyright(c) 2020 Google Inc. */ -// There are basically two major "container" families for modern audio-visual formats: -// 1) the ISO-BMFF family (MP4, HEVC, AVIF, etc) -// 2) the Matroska family (MKV, WebM, WebP) +// A Container Format is a file that embeds multiple data streams into a single file. +// Relevant examples: +// 1) the ISO-BMFF family (MP4, HEVC, AVIF, MOV/QT, etc) +// 2) the Matroska family (MKV, WebM) +// 3) the RIFF family (WAV, AVI, WebP) +// 4) the OGG family (OGV, OPUS) +// 5) the ZIP family (ZIP, JAR, CBZ, EPUB, ODF, OOXML) // The ISO-BMFF container needs special processing because of its "compatible brands" array :( // The Matroska container needs special processing because the sub-type can appear anywhere :( +// The OGG container needs special processing to determine what kind of streams are present :( +// The ZIP container needs special processing to determine what files are present inside it :( // NOTE: Because the ICO format also starts with a couple zero bytes, this tree will rely on the // File Type box never going beyond 255 bytes in length which, seems unlikely according to @@ -58,6 +64,8 @@ const fileSignatures = { [0xFF, 0xF2], [0x49, 0x44, 0x33], // 'ID3' ], + 'audio/wav': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x41, 0x56, 0x45]], // 'RIFF....WAVE' + 'video/avi': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x41, 0x56, 0x49, 0x20]], // 'RIFF....AVI ' }; // TODO: Eventually add support for various container formats so that: diff --git a/tests/file-sniffer.spec.js b/tests/file-sniffer.spec.js index b24d6d6..89c4eb3 100644 --- a/tests/file-sniffer.spec.js +++ b/tests/file-sniffer.spec.js @@ -38,4 +38,6 @@ describe('bitjs.file.sniffer', () => { it('TAR_1', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30]); }); it('TAR_2', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00]); }); it('FLAC', () => { sniffTest('audio/flac', [0x66, 0x4C, 0x61, 0x43]); }); + it('WAV', () => { sniffTest('audio/wav', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x57, 0x41, 0x56, 0x45, 0x81]); }); + it('AVI', () => { sniffTest('video/avi', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x41, 0x56, 0x49, 0x20, 0x81]); }); });