Skip to content

Commit 2eb77ef

Browse files
committed
Add WOFF, WOFF2 to file sniffer
1 parent 244dfed commit 2eb77ef

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

file/sniffer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// A Container Format is a file that embeds multiple data streams into a single file.
11-
// Relevant examples:
11+
// Examples:
1212
// 1) the ISO-BMFF family (MP4, HEVC, AVIF, MOV/QT, etc)
1313
// 2) the Matroska family (MKV, WebM)
1414
// 3) the RIFF family (WAV, AVI, WebP)
@@ -66,6 +66,10 @@ const fileSignatures = {
6666
],
6767
'audio/wav': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x41, 0x56, 0x45]], // 'RIFF....WAVE'
6868
'video/avi': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x41, 0x56, 0x49, 0x20]], // 'RIFF....AVI '
69+
70+
// Miscellaneous.
71+
'font/woff': [[0x77, 0x4F, 0x46, 0x46]], // 'wOFF'
72+
'font/woff2': [[0x77, 0x4F, 0x46, 0x32]], // 'wOF2'
6973
};
7074

7175
// TODO: Eventually add support for various container formats so that:
@@ -102,7 +106,7 @@ let maxDepth = 0;
102106
export function initialize() {
103107
root = new Node();
104108

105-
// Construct the tree, erroring if overlapping mime types are possible.
109+
// Construct the tree, erroring if overlapping mime types are found.
106110
for (const mimeType in fileSignatures) {
107111
for (const signature of fileSignatures[mimeType]) {
108112
let curNode = root;

tests/file-sniffer.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ describe('bitjs.file.sniffer', () => {
4040
it('FLAC', () => { sniffTest('audio/flac', [0x66, 0x4C, 0x61, 0x43]); });
4141
it('WAV', () => { sniffTest('audio/wav', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x57, 0x41, 0x56, 0x45, 0x81]); });
4242
it('AVI', () => { sniffTest('video/avi', [0x52, 0x49, 0x46, 0x46, 0x01, 0x02, 0x03, 0x04, 0x41, 0x56, 0x49, 0x20, 0x81]); });
43+
it('WOFF', () => { sniffTest('font/woff', [0x77, 0x4F, 0x46, 0x46, 0x80]); });
44+
it('WOFF2', () => { sniffTest('font/woff2', [0x77, 0x4F, 0x46, 0x32, 0x80]); });
4345
});

0 commit comments

Comments
 (0)