mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 17:49:16 +02:00
Add WOFF, WOFF2 to file sniffer
This commit is contained in:
parent
244dfed5d9
commit
2eb77ef59c
2 changed files with 8 additions and 2 deletions
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// A Container Format is a file that embeds multiple data streams into a single file.
|
// A Container Format is a file that embeds multiple data streams into a single file.
|
||||||
// Relevant examples:
|
// Examples:
|
||||||
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, MOV/QT, etc)
|
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, MOV/QT, etc)
|
||||||
// 2) the Matroska family (MKV, WebM)
|
// 2) the Matroska family (MKV, WebM)
|
||||||
// 3) the RIFF family (WAV, AVI, WebP)
|
// 3) the RIFF family (WAV, AVI, WebP)
|
||||||
|
@ -66,6 +66,10 @@ const fileSignatures = {
|
||||||
],
|
],
|
||||||
'audio/wav': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x41, 0x56, 0x45]], // 'RIFF....WAVE'
|
'audio/wav': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x41, 0x56, 0x45]], // 'RIFF....WAVE'
|
||||||
'video/avi': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x41, 0x56, 0x49, 0x20]], // 'RIFF....AVI '
|
'video/avi': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x41, 0x56, 0x49, 0x20]], // 'RIFF....AVI '
|
||||||
|
|
||||||
|
// Miscellaneous.
|
||||||
|
'font/woff': [[0x77, 0x4F, 0x46, 0x46]], // 'wOFF'
|
||||||
|
'font/woff2': [[0x77, 0x4F, 0x46, 0x32]], // 'wOF2'
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Eventually add support for various container formats so that:
|
// TODO: Eventually add support for various container formats so that:
|
||||||
|
@ -102,7 +106,7 @@ let maxDepth = 0;
|
||||||
export function initialize() {
|
export function initialize() {
|
||||||
root = new Node();
|
root = new Node();
|
||||||
|
|
||||||
// Construct the tree, erroring if overlapping mime types are possible.
|
// Construct the tree, erroring if overlapping mime types are found.
|
||||||
for (const mimeType in fileSignatures) {
|
for (const mimeType in fileSignatures) {
|
||||||
for (const signature of fileSignatures[mimeType]) {
|
for (const signature of fileSignatures[mimeType]) {
|
||||||
let curNode = root;
|
let curNode = root;
|
||||||
|
|
|
@ -40,4 +40,6 @@ describe('bitjs.file.sniffer', () => {
|
||||||
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('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]); });
|
it('AVI', () => { sniffTest('video/avi', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x41, 0x56, 0x49, 0x20, 0x81]); });
|
||||||
|
it('WOFF', () => { sniffTest('font/woff', [0x77, 0x4F, 0x46, 0x46, 0x80]); });
|
||||||
|
it('WOFF2', () => { sniffTest('font/woff2', [0x77, 0x4F, 0x46, 0x32, 0x80]); });
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue