mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 17:49:16 +02:00
Add WAV and AVI types to the file sniffer
This commit is contained in:
parent
4854b9754f
commit
244dfed5d9
2 changed files with 13 additions and 3 deletions
|
@ -7,12 +7,18 @@
|
||||||
* Copyright(c) 2020 Google Inc.
|
* Copyright(c) 2020 Google Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// There are basically two major "container" families for modern audio-visual formats:
|
// A Container Format is a file that embeds multiple data streams into a single file.
|
||||||
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, etc)
|
// Relevant examples:
|
||||||
// 2) the Matroska family (MKV, WebM, WebP)
|
// 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 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 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
|
// 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
|
// File Type box never going beyond 255 bytes in length which, seems unlikely according to
|
||||||
|
@ -58,6 +64,8 @@ const fileSignatures = {
|
||||||
[0xFF, 0xF2],
|
[0xFF, 0xF2],
|
||||||
[0x49, 0x44, 0x33], // 'ID3'
|
[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:
|
// TODO: Eventually add support for various container formats so that:
|
||||||
|
|
|
@ -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_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('TAR_2', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00]); });
|
||||||
it('FLAC', () => { sniffTest('audio/flac', [0x66, 0x4C, 0x61, 0x43]); });
|
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]); });
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue