detect-file-type
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "detect-file-type", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Detect file type by signature", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ # detect-file-type | ||
### Поддерживаемые типы (будет пополнятся) | ||
jpg, png, gif, bmp, webp, tif, cr2, jxr, psd, zip, epub, xpi, tar, rar, gz, bz2, 7z, dmg, mp4, m4v | ||
jpg, png, gif, bmp, webp, tif, cr2, jxr, psd, zip, epub, xpi, tar, rar, gz, bz2, 7z, dmg, mp4, m4v, midi, mkv, webm, wmv, mpg, mp3, m4a, opus, ogg, flac, wav, amr, pdf, exe, swf, rtf | ||
@@ -9,0 +9,0 @@ ## Usage |
@@ -6,3 +6,3 @@ # detect-file-type [![Build Status](https://travis-ci.org/dimapaloskin/detect-file-type.svg?branch=master)](https://travis-ci.org/dimapaloskin/detect-file-type) | ||
### Supported types (will be updated) | ||
jpg, png, gif, bmp, webp, tif, cr2, jxr, psd, zip, epub, xpi, tar, rar, gz, bz2, 7z, dmg, mp4, m4v | ||
jpg, png, gif, bmp, webp, tif, cr2, jxr, psd, zip, epub, xpi, tar, rar, gz, bz2, 7z, dmg, mp4, m4v, midi, mkv, webm, wmv, mpg, mp3, m4a, opus, ogg, flac, wav, amr, pdf, exe, swf, rtf | ||
@@ -9,0 +9,0 @@ ## Installation |
@@ -242,3 +242,186 @@ [ | ||
] | ||
}, | ||
{ | ||
"type": "mid", | ||
"ext": "mid", | ||
"mime": "audio/midi", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d546864" } | ||
] | ||
}, | ||
{ | ||
"type": "mkv", | ||
"ext": "mkv", | ||
"mime": "video/x-matroska", | ||
"rules": [ | ||
{ "type": "equal", "start": 31, "end": 39, "bytes": "6d6174726f736b61" } | ||
] | ||
}, | ||
{ | ||
"type": "webm", | ||
"ext": "webm", | ||
"mime": "video/webm", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "1a45dfa3" }, | ||
{ "type": "notEqual", "start": 31, "end": 39, "bytes": "6d6174726f736b61" } | ||
] | ||
}, | ||
{ | ||
"type": "wmv", | ||
"ext": "wmv", | ||
"mime": "video/x-ms-wmv", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 10, "bytes": "3026b2758e66cf11a6d9" } | ||
] | ||
}, | ||
{ | ||
"type": "mpg", | ||
"ext": "mpg", | ||
"mime": "video/mpeg", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 3, "bytes": "000001" }, | ||
{ "type": "or", "rules": | ||
[ | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b0"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b1"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b2"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b3"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b4"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b5"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b6"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b7"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b8"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "b9"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "ba"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "bb"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "bc"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "bd"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "be"}, | ||
{ "type": "equal", "start": 3, "end": 4, "bytes": "bf"} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "mp3", | ||
"ext": "mp3", | ||
"mime": "audio/mpeg", | ||
"rules": [ | ||
{ "type": "or", "rules": | ||
[ | ||
{ "type": "equal", "start": 0, "end": 3, "bytes": "494433" }, | ||
{ "type": "equal", "start": 0, "end": 2, "bytes": "fffb" } | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "m4a", | ||
"ext": "m4a", | ||
"mime": "audio/m4a", | ||
"rules": [ | ||
{ "type": "or", "rules": | ||
[ | ||
{ "type": "equal", "start": 4, "end": 11, "bytes": "667479704d3441" }, | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d344120" } | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "opus", | ||
"ext": "opus", | ||
"mime": "audio/opus", | ||
"rules": [ | ||
{ "type": "equal", "start": 28, "end": 36, "bytes": "4f70757348656164" } | ||
] | ||
}, | ||
{ | ||
"type": "ogg", | ||
"ext": "ogg", | ||
"mime": "audio/ogg", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "4f676753" }, | ||
{ "type": "notEqual", "start": 28, "end": 36, "bytes": "4f70757348656164" } | ||
] | ||
}, | ||
{ | ||
"type": "flac", | ||
"ext": "flac", | ||
"mime": "audio/x-flac", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "664c6143" } | ||
] | ||
}, | ||
{ | ||
"type": "wav", | ||
"ext": "wav", | ||
"mime": "audio/x-wav", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "52494646" }, | ||
{ "type": "equal", "start": 8, "end": 12, "bytes": "57415645" } | ||
] | ||
}, | ||
{ | ||
"type": "amr", | ||
"ext": "amr", | ||
"mime": "audio/amr", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 6, "bytes": "2321414d520a" } | ||
] | ||
}, | ||
{ | ||
"type": "pdf", | ||
"ext": "pdf", | ||
"mime": "application/pdf", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 4, "bytes": "25504446" } | ||
] | ||
}, | ||
{ | ||
"type": "exe", | ||
"ext": "exe", | ||
"mime": "application/x-msdownload", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 2, "bytes": "4d5a" } | ||
] | ||
}, | ||
{ | ||
"type": "swf", | ||
"ext": "swf", | ||
"mime": "application/x-shockwave-flash", | ||
"rules": [ | ||
{ "type": "or", "rules": | ||
[ | ||
{ "type": "equal", "start": 0, "end": 1, "bytes": "43" }, | ||
{ "type": "equal", "start": 0, "end": 1, "bytes": "46" } | ||
] | ||
}, | ||
{ "type": "equal", "start": 1, "end": 3, "bytes": "5753" } | ||
] | ||
}, | ||
{ | ||
"type": "rtf", | ||
"ext": "rtf", | ||
"mime": "application/rtf", | ||
"rules": [ | ||
{ "type": "equal", "start": 0, "end": 5, "bytes": "7b5c727466" } | ||
] | ||
} | ||
] |
176
src/test.js
@@ -237,2 +237,178 @@ import {assert} from 'chai'; | ||
it('should detect midi', (done) => { | ||
detect.fromFile('./files/fixture.mid', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'mid', | ||
mime: 'audio/midi' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mkv', (done) => { | ||
detect.fromFile('./files/fixture.mkv', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'mkv', | ||
mime: 'video/x-matroska' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect webm', (done) => { | ||
detect.fromFile('./files/fixture.webm', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'webm', | ||
mime: 'video/webm' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect wmv', (done) => { | ||
detect.fromFile('./files/fixture.wmv', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'wmv', | ||
mime: 'video/x-ms-wmv' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mpg', (done) => { | ||
detect.fromFile('./files/fixture.mpg', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'mpg', | ||
mime: 'video/mpeg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mp3', (done) => { | ||
detect.fromFile('./files/fixture.mp3', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'mp3', | ||
mime: 'audio/mpeg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect m4a', (done) => { | ||
detect.fromFile('./files/fixture.m4a', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'm4a', | ||
mime: 'audio/m4a' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect opus', (done) => { | ||
detect.fromFile('./files/fixture.opus', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'opus', | ||
mime: 'audio/opus' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect ogg', (done) => { | ||
detect.fromFile('./files/fixture.ogg', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'ogg', | ||
mime: 'audio/ogg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect flac', (done) => { | ||
detect.fromFile('./files/fixture.flac', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'flac', | ||
mime: 'audio/x-flac' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect wav', (done) => { | ||
detect.fromFile('./files/fixture.wav', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'wav', | ||
mime: 'audio/x-wav' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect amr', (done) => { | ||
detect.fromFile('./files/fixture.amr', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'amr', | ||
mime: 'audio/amr' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect pdf', (done) => { | ||
detect.fromFile('./files/fixture.pdf', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'pdf', | ||
mime: 'application/pdf' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect exe', (done) => { | ||
detect.fromFile('./files/fixture.exe', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'exe', | ||
mime: 'application/x-msdownload' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect swf', (done) => { | ||
detect.fromFile('./files/fixture.swf', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'swf', | ||
mime: 'application/x-shockwave-flash' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect rtf', (done) => { | ||
detect.fromFile('./files/fixture.rtf', (err, result) => { | ||
assert.equal(err, null); | ||
assert.deepEqual(result, { | ||
ext: 'rtf', | ||
mime: 'application/rtf' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
176
test.js
@@ -243,2 +243,178 @@ 'use strict'; | ||
}); | ||
it('should detect midi', function (done) { | ||
_index2.default.fromFile('./files/fixture.mid', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'mid', | ||
mime: 'audio/midi' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mkv', function (done) { | ||
_index2.default.fromFile('./files/fixture.mkv', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'mkv', | ||
mime: 'video/x-matroska' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect webm', function (done) { | ||
_index2.default.fromFile('./files/fixture.webm', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'webm', | ||
mime: 'video/webm' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect wmv', function (done) { | ||
_index2.default.fromFile('./files/fixture.wmv', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'wmv', | ||
mime: 'video/x-ms-wmv' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mpg', function (done) { | ||
_index2.default.fromFile('./files/fixture.mpg', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'mpg', | ||
mime: 'video/mpeg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect mp3', function (done) { | ||
_index2.default.fromFile('./files/fixture.mp3', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'mp3', | ||
mime: 'audio/mpeg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect m4a', function (done) { | ||
_index2.default.fromFile('./files/fixture.m4a', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'm4a', | ||
mime: 'audio/m4a' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect opus', function (done) { | ||
_index2.default.fromFile('./files/fixture.opus', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'opus', | ||
mime: 'audio/opus' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect ogg', function (done) { | ||
_index2.default.fromFile('./files/fixture.ogg', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'ogg', | ||
mime: 'audio/ogg' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect flac', function (done) { | ||
_index2.default.fromFile('./files/fixture.flac', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'flac', | ||
mime: 'audio/x-flac' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect wav', function (done) { | ||
_index2.default.fromFile('./files/fixture.wav', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'wav', | ||
mime: 'audio/x-wav' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect amr', function (done) { | ||
_index2.default.fromFile('./files/fixture.amr', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'amr', | ||
mime: 'audio/amr' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect pdf', function (done) { | ||
_index2.default.fromFile('./files/fixture.pdf', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'pdf', | ||
mime: 'application/pdf' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect exe', function (done) { | ||
_index2.default.fromFile('./files/fixture.exe', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'exe', | ||
mime: 'application/x-msdownload' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect swf', function (done) { | ||
_index2.default.fromFile('./files/fixture.swf', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'swf', | ||
mime: 'application/x-shockwave-flash' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should detect rtf', function (done) { | ||
_index2.default.fromFile('./files/fixture.rtf', function (err, result) { | ||
_chai.assert.equal(err, null); | ||
_chai.assert.deepEqual(result, { | ||
ext: 'rtf', | ||
mime: 'application/rtf' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16184022
1580