Permalink
Browse files

Close #41 PR: Added handful of compressed file types.

  • Loading branch information...
alexanderlperez authored and sindresorhus committed Nov 8, 2015
1 parent 14a48a3 commit 17911e2de88050ce775fbf952ad2a84bd623b6dc
BIN +109 KB fixture/fixture.ar
Binary file not shown.
BIN +136 KB fixture/fixture.cab
Binary file not shown.
BIN +43.9 KB fixture/fixture.deb
Binary file not shown.
BIN +242 Bytes fixture/fixture.tar.Z
Binary file not shown.
BIN +2.14 KB fixture/fixture.tar.lz
Binary file not shown.
BIN +109 KB fixture/fixture.xpi
Binary file not shown.
@@ -76,6 +76,15 @@ module.exports = function (buf) {
};
}

// needs to be before `zip` check
// assumes signed .xpi from addons.mozilla.org
if (buf[0] === 0x50 && buf[1] === 0x4B && buf[2] === 0x3 && buf[3] === 0x4 && buf[30] === 0x4D && buf[31] === 0x45 && buf[32] === 0x54 && buf[33] === 0x41 && buf[34] === 0x2D && buf[35] === 0x49 && buf[36] === 0x4E && buf[37] === 0x46 && buf[38] === 0x2F && buf[39] === 0x6D && buf[40] === 0x6F && buf[41] === 0x7A && buf[42] === 0x69 && buf[43] === 0x6C && buf[44] === 0x6C && buf[45] === 0x61 && buf[46] === 0x2E && buf[47] === 0x72 && buf[48] === 0x73 && buf[49] === 0x61) {
return {
ext: 'xpi',
mime: 'application/x-xpinstall'
};
}

if (buf[0] === 0x50 && buf[1] === 0x4B && (buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) && (buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8)) {
return {
ext: 'zip',
@@ -348,5 +357,47 @@ module.exports = function (buf) {
};
}

if (
(buf[0] === 0x4D && buf[1] === 0x53 && buf[2] === 0x43 && buf[3] === 0x46) ||
(buf[0] === 0x49 && buf[1] === 0x53 && buf[2] === 0x63 && buf[3] === 0x28)
) {
return {
ext: 'cab',
mime: 'application/vnd.ms-cab-compressed'
};
}

// needs to be before `ar` check
if (buf[0] === 0x21 && buf[1] === 0x3C && buf[2] === 0x61 && buf[3] === 0x72 && buf[4] === 0x63 && buf[5] === 0x68 && buf[6] === 0x3E && buf[7] === 0x0A && buf[8] === 0x64 && buf[9] === 0x65 && buf[10] === 0x62 && buf[11] === 0x69 && buf[12] === 0x61 && buf[13] === 0x6E && buf[14] === 0x2D && buf[15] === 0x62 && buf[16] === 0x69 && buf[17] === 0x6E && buf[18] === 0x61 && buf[19] === 0x72 && buf[20] === 0x79) {
return {
ext: 'deb',
mime: 'application/x-deb'
};
}

if (buf[0] === 0x21 && buf[1] === 0x3C && buf[2] === 0x61 && buf[3] === 0x72 && buf[4] === 0x63 && buf[5] === 0x68 && buf[6] === 0x3E) {
return {
ext: 'ar',
mime: 'application/x-unix-archive'
};
}

if (
(buf[0] === 0x1F && buf[1] === 0xA0) ||
(buf[0] === 0x1F && buf[1] === 0x9D)
) {
return {
ext: 'Z',
mime: 'application/x-compress'
};
}

if (buf[0] === 0x4C && buf[1] === 0x5A && buf[2] === 0x49 && buf[3] === 0x50) {
return {
ext: 'lz',
mime: 'application/x-lzip'
};
}

return null;
};
@@ -83,7 +83,13 @@
"flv",
"ps",
"xz",
"sqlite"
"sqlite",
"xpi",
"cab",
"deb",
"ar",
"Z",
"lz"
],
"devDependencies": {
"ava": "*",
@@ -123,6 +123,12 @@ It only needs the first 262 bytes.
- `sqlite`
- `nes`
- `crx`
- `xpi`
- `cab`
- `deb`
- `ar`
- `Z`
- `lz`

*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*

12 test.js
@@ -56,14 +56,22 @@ const types = [
'xz',
'sqlite',
'nes',
'crx'
'crx',
'xpi',
'cab',
'deb',
'ar',
'Z',
'lz'
];

const names = {
mp4: ['fixture-imovie', 'fixture-isom'],
tif: ['fixture-big-endian', 'fixture-little-endian'],
gz: ['fixture.tar'],
xz: ['fixture.tar']
xz: ['fixture.tar'],
lz: ['fixture.tar'],
Z: ['fixture.tar']
};

function testFile(type, name) {

0 comments on commit 17911e2

Please sign in to comment.