file-type
Advanced tools
Comparing version
10
index.js
'use strict'; | ||
module.exports = function (buf) { | ||
if (!buf || buf.length < 12) { | ||
if (!buf) { | ||
return false; | ||
} | ||
if (require('is-pdf')(buf)) { | ||
return 'pdf'; | ||
} | ||
if (require('is-epub')(buf)) { | ||
return 'epub'; | ||
} | ||
return require('image-type')(buf) || require('archive-type')(buf) || false; | ||
}; |
{ | ||
"name": "file-type", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Detect the file type of a Buffer/Uint8Array", | ||
@@ -63,2 +63,4 @@ "license": "MIT", | ||
"image-type": "^0.1.1", | ||
"is-epub": "^0.1.0", | ||
"is-pdf": "^0.1.0", | ||
"read-chunk": "^0.1.0" | ||
@@ -65,0 +67,0 @@ }, |
@@ -28,3 +28,3 @@ # file-type [](https://travis-ci.org/sindresorhus/file-type) | ||
var fileType = require('file-type'); | ||
var buffer = readChunk('unicorn.png', 0, 12); | ||
var buffer = readChunk('unicorn.png', 0, 58); | ||
@@ -61,3 +61,3 @@ fileType(buffer); | ||
It only needs the first 12 bytes. | ||
It only needs the first 58 bytes. | ||
@@ -100,2 +100,4 @@ | ||
- [`zip`](https://github.com/kevva/is-zip) | ||
- [`pdf`](https://github.com/kevva/is-pdf) | ||
- [`epub`](https://github.com/sindresorhus/is-epub) | ||
@@ -102,0 +104,0 @@ *PR welcome for additional file types* |
4531
5.32%58
11.54%107
1.9%5
66.67%+ Added
+ Added
+ Added
+ Added