file-type
Advanced tools
Comparing version 0.3.0 to 1.0.0
36
cli.js
@@ -5,15 +5,19 @@ #!/usr/bin/env node | ||
var pkg = require('./package.json'); | ||
var fileType = require('./index'); | ||
var input = process.argv[2]; | ||
var fileType = require('./'); | ||
var argv = process.argv.slice(2); | ||
var input = argv[0]; | ||
function help() { | ||
console.log(pkg.description); | ||
console.log(''); | ||
console.log('Usage'); | ||
console.log(' $ cat <filename> | file-type'); | ||
console.log(' $ file-type <filename>'); | ||
console.log(''); | ||
console.log('Example'); | ||
console.log(' $ cat unicorn.png | file-type'); | ||
console.log(' png'); | ||
console.log([ | ||
'', | ||
' ' + pkg.description, | ||
'', | ||
' Usage', | ||
' file-type <filename>', | ||
' cat <filename> | file-type', | ||
'', | ||
' Example', | ||
' cat unicorn.png | file-type', | ||
' png' | ||
].join('\n')); | ||
} | ||
@@ -32,3 +36,3 @@ | ||
if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { | ||
if (argv.indexOf('--help') !== -1) { | ||
help(); | ||
@@ -38,3 +42,3 @@ return; | ||
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { | ||
if (argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version); | ||
@@ -50,7 +54,5 @@ return; | ||
init(readChunk.sync(input, 0, 12)); | ||
init(readChunk.sync(input, 0, 262)); | ||
} else { | ||
process.stdin.once('data', function (data) { | ||
init(data); | ||
}); | ||
process.stdin.once('data', init); | ||
} |
@@ -21,5 +21,9 @@ 'use strict'; | ||
return 'mp4'; | ||
} | ||
} | ||
return require('image-type')(buf) || require('archive-type')(buf) || require ('audio-type')(buf)|| false; | ||
if (require('is-swf')(buf)) { | ||
return 'swf'; | ||
} | ||
return require('image-type')(buf) || require('archive-type')(buf) || require ('audio-type')(buf) || false; | ||
}; |
{ | ||
"name": "file-type", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Detect the file type of a Buffer/Uint8Array", | ||
"license": "MIT", | ||
"repository": "sindresorhus/file-type", | ||
"bin": { | ||
"file-type": "cli.js" | ||
}, | ||
"author": { | ||
@@ -15,2 +12,5 @@ "name": "Sindre Sorhus", | ||
}, | ||
"bin": { | ||
"file-type": "cli.js" | ||
}, | ||
"engines": { | ||
@@ -20,4 +20,3 @@ "node": ">=0.10.0" | ||
"scripts": { | ||
"test": "mocha", | ||
"browser": "browserify -s $npm_package_name -o browser.js ." | ||
"test": "mocha" | ||
}, | ||
@@ -29,2 +28,3 @@ "files": [ | ||
"keywords": [ | ||
"mime", | ||
"file", | ||
@@ -37,2 +37,3 @@ "type", | ||
"picture", | ||
"flash", | ||
"photo", | ||
@@ -63,2 +64,3 @@ "video", | ||
"rar", | ||
"swf", | ||
"tar", | ||
@@ -69,15 +71,15 @@ "zip", | ||
"dependencies": { | ||
"archive-type": "^0.1.1", | ||
"audio-type": "^0.1.0", | ||
"image-type": "^0.1.1", | ||
"is-epub": "^0.1.0", | ||
"archive-type": "^0.1.4", | ||
"audio-type": "^0.1.4", | ||
"image-type": "^1.0.0", | ||
"is-epub": "^0.1.2", | ||
"is-exe": "^0.1.0", | ||
"is-mp4": "^0.1.0", | ||
"is-pdf": "^0.1.0", | ||
"read-chunk": "^0.1.0", | ||
"is-mp4": "^0.1.0" | ||
"is-swf": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^3.0.0", | ||
"mocha": "*" | ||
"mocha": "*", | ||
"read-chunk": "^1.0.0" | ||
} | ||
} |
@@ -14,11 +14,3 @@ # file-type [![Build Status](https://travis-ci.org/sindresorhus/file-type.svg?branch=master)](https://travis-ci.org/sindresorhus/file-type) | ||
```sh | ||
$ bower install --save file-type | ||
``` | ||
```sh | ||
$ component install sindresorhus/file-type | ||
``` | ||
## Usage | ||
@@ -37,2 +29,18 @@ | ||
or from a remote location: | ||
```js | ||
var http = require('http'); | ||
var fileType = require('file-type'); | ||
var url = 'http://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif'; | ||
http.get(url, function (res) { | ||
res.once('data', function (chunk) { | ||
res.destroy(); | ||
console.log(fileType(chunk)); | ||
//=> gif | ||
}); | ||
}); | ||
``` | ||
##### Browser | ||
@@ -76,9 +84,9 @@ | ||
Usage | ||
$ cat <filename> | file-type | ||
$ file-type <filename> | ||
Usage | ||
file-type <filename> | ||
cat <filename> | file-type | ||
Example | ||
$ cat unicorn.png | file-type | ||
png | ||
Example | ||
cat unicorn.png | file-type | ||
png | ||
``` | ||
@@ -112,6 +120,7 @@ | ||
- [`mp4`](https://github.com/deepak1556/is-mp4) | ||
- [`swf`](https://github.com/kevva/is-swf) | ||
*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).* | ||
*PR welcome for additional commonly used file types* | ||
*PR welcome for additional commonly used file types.* | ||
@@ -118,0 +127,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5533
69
1
127
+ Addedis-swf@^0.1.0
+ Addedcamelcase@1.2.1(transitive)
+ Addedcamelcase-keys@1.0.0(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedimage-type@1.1.0(transitive)
+ Addedindent-string@1.2.2(transitive)
+ Addedis-bmp@1.0.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-gif@1.0.0(transitive)
+ Addedis-jpg@1.0.1(transitive)
+ Addedis-jxr@1.0.1(transitive)
+ Addedis-png@1.1.0(transitive)
+ Addedis-psd@1.0.1(transitive)
+ Addedis-swf@0.1.0(transitive)
+ Addedis-tif@1.0.1(transitive)
+ Addedis-webp@1.0.1(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@2.1.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedobject-assign@2.1.1(transitive)
+ Addedrepeating@1.1.3(transitive)
- Removedread-chunk@^0.1.0
- Removedimage-type@0.1.4(transitive)
- Removedis-bmp@0.1.1(transitive)
- Removedis-gif@0.1.1(transitive)
- Removedis-jpg@0.1.2(transitive)
- Removedis-jxr@0.1.1(transitive)
- Removedis-png@0.1.1(transitive)
- Removedis-psd@0.1.1(transitive)
- Removedis-tif@0.1.1(transitive)
- Removedis-webp@0.1.1(transitive)
Updatedarchive-type@^0.1.4
Updatedaudio-type@^0.1.4
Updatedimage-type@^1.0.0
Updatedis-epub@^0.1.2