file-type
Advanced tools
Comparing version 7.2.0 to 7.3.0
48
index.js
@@ -14,15 +14,15 @@ 'use strict'; | ||
const check = (header, opts) => { | ||
opts = Object.assign({ | ||
const check = (header, options) => { | ||
options = Object.assign({ | ||
offset: 0 | ||
}, opts); | ||
}, options); | ||
for (let i = 0; i < header.length; i++) { | ||
// If a bitmask is set | ||
if (opts.mask) { | ||
if (options.mask) { | ||
// If header doesn't equal `buf` with bits masked off | ||
if (header[i] !== (opts.mask[i] & buf[i + opts.offset])) { | ||
if (header[i] !== (options.mask[i] & buf[i + options.offset])) { | ||
return false; | ||
} | ||
} else if (header[i] !== buf[i + opts.offset]) { | ||
} else if (header[i] !== buf[i + options.offset]) { | ||
return false; | ||
@@ -35,2 +35,4 @@ } | ||
const checkString = (header, options) => check(toBytes(header), options); | ||
if (check([0xFF, 0xD8, 0xFF])) { | ||
@@ -133,2 +135,23 @@ return { | ||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.text', {offset: 30})) { | ||
return { | ||
ext: 'odt', | ||
mime: 'application/vnd.oasis.opendocument.text' | ||
}; | ||
} | ||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.spreadsheet', {offset: 30})) { | ||
return { | ||
ext: 'ods', | ||
mime: 'application/vnd.oasis.opendocument.spreadsheet' | ||
}; | ||
} | ||
if (checkString('mimetypeapplication/vnd.oasis.opendocument.presentation', {offset: 30})) { | ||
return { | ||
ext: 'odp', | ||
mime: 'application/vnd.oasis.opendocument.presentation' | ||
}; | ||
} | ||
// https://github.com/file/file/blob/master/magic/Magdir/msooxml | ||
@@ -147,3 +170,3 @@ if (check(oxmlContentTypes, {offset: 30}) || check(oxmlRels, {offset: 30})) { | ||
if (check(toBytes('word/'), {offset})) { | ||
if (checkString('word/', {offset})) { | ||
return { | ||
@@ -155,3 +178,3 @@ ext: 'docx', | ||
if (check(toBytes('ppt/'), {offset})) { | ||
if (checkString('ppt/', {offset})) { | ||
return { | ||
@@ -163,3 +186,3 @@ ext: 'pptx', | ||
if (check(toBytes('xl/'), {offset})) { | ||
if (checkString('xl/', {offset})) { | ||
return { | ||
@@ -692,3 +715,10 @@ ext: 'xlsx', | ||
if (checkString('<?xml ')) { | ||
return { | ||
ext: 'xml', | ||
mime: 'application/xml' | ||
}; | ||
} | ||
return null; | ||
}; |
{ | ||
"name": "file-type", | ||
"version": "7.2.0", | ||
"version": "7.3.0", | ||
"description": "Detect the file type of a Buffer/Uint8Array", | ||
@@ -109,3 +109,7 @@ "license": "MIT", | ||
"mj2", | ||
"aif" | ||
"aif", | ||
"odt", | ||
"ods", | ||
"odp", | ||
"xml" | ||
], | ||
@@ -112,0 +116,0 @@ "devDependencies": { |
@@ -156,2 +156,6 @@ # file-type [](https://travis-ci.org/sindresorhus/file-type) | ||
- [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format) | ||
- [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for word processing | ||
- [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for spreadsheets | ||
- [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations | ||
- [`xml`](https://en.wikipedia.org/wiki/XML) | ||
@@ -158,0 +162,0 @@ *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).* |
23531
625
180