forked from sindresorhus/file-type
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
46 lines (44 loc) · 1.51 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
var path = require('path');
var test = require('ava');
var readChunk = require('read-chunk');
var fileType = require('./');
function check(ext, name) {
var file = path.join(__dirname, 'fixture', (name || 'fixture') + '.' + ext);
return fileType(readChunk.sync(file, 0, 262)).ext;
}
test('detect file type from a buffer', function (t) {
t.assert(check('jpg') === 'jpg');
t.assert(check('png') === 'png');
t.assert(check('gif') === 'gif');
t.assert(check('webp') === 'webp');
t.assert(check('tif', 'fixture-big-endian') === 'tif');
t.assert(check('tif', 'fixture-little-endian') === 'tif');
t.assert(check('bmp') === 'bmp');
t.assert(check('jxr') === 'jxr');
t.assert(check('psd') === 'psd');
t.assert(check('zip') === 'zip');
t.assert(check('tar') === 'tar');
t.assert(check('rar') === 'rar');
t.assert(check('tar.gz') === 'gz');
t.assert(check('bz2') === 'bz2');
t.assert(check('7z') === '7z');
t.assert(check('mp4') === 'mp4');
t.assert(check('mkv') === 'mkv');
t.assert(check('webm') === 'webm');
t.assert(check('mov') === 'mov');
t.assert(check('avi') === 'avi');
t.assert(check('mpg') === 'mpg');
t.assert(check('wmv') === 'wmv');
t.assert(check('mp3') === 'mp3');
t.assert(check('m4a') === 'm4a');
t.assert(check('ogg') === 'ogg');
t.assert(check('flac') === 'flac');
t.assert(check('wav') === 'wav');
t.assert(check('pdf') === 'pdf');
t.assert(check('epub') === 'epub');
t.assert(check('exe') === 'exe');
t.assert(check('swf') === 'swf');
t.assert(check('rtf') === 'rtf');
t.end();
});