archive-type
Advanced tools
Comparing version 3.2.0 to 4.0.0
28
index.js
'use strict'; | ||
var fileType = require('file-type'); | ||
const fileType = require('file-type'); | ||
module.exports = function (buf) { | ||
var ret = fileType(buf); | ||
var exts = [ | ||
'7z', | ||
'bz2', | ||
'gz', | ||
'rar', | ||
'tar', | ||
'zip', | ||
'xz', | ||
'gz' | ||
]; | ||
const exts = new Set([ | ||
'7z', | ||
'bz2', | ||
'gz', | ||
'rar', | ||
'tar', | ||
'zip', | ||
'xz', | ||
'gz' | ||
]); | ||
return exts.indexOf(ret && ret.ext) !== -1 ? ret : null; | ||
module.exports = input => { | ||
const ret = fileType(input); | ||
return exts.has(ret && ret.ext) ? ret : null; | ||
}; |
{ | ||
"name": "archive-type", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "Detect the archive type of a Buffer/Uint8Array", | ||
@@ -13,6 +13,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "node test/test.js" | ||
"test": "xo && ava" | ||
}, | ||
@@ -35,15 +35,13 @@ "files": [ | ||
"zip", | ||
"file", | ||
"type" | ||
], | ||
"dependencies": { | ||
"file-type": "^3.1.0" | ||
"file-type": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.0.4" | ||
}, | ||
"xo": { | ||
"rules": { | ||
"no-negated-condition": 0 | ||
} | ||
"ava": "*", | ||
"pify": "^2.3.0", | ||
"xo": "*" | ||
} | ||
} |
@@ -5,5 +5,3 @@ # archive-type [![Build Status](https://travis-ci.org/kevva/archive-type.svg?branch=master)](https://travis-ci.org/kevva/archive-type) | ||
*See [archive-type-cli](https://github.com/kevva/archive-type-cli) for the command-line version.* | ||
## Install | ||
@@ -19,6 +17,7 @@ | ||
```js | ||
var readFileSync = require('fs').readFileSync; | ||
var archiveType = require('archive-type'); | ||
const archiveType = require('archive-type'); | ||
const readChunk = require('read-chunk'); | ||
const buffer = readChunk.sync('unicorn.zip', 0, 262); | ||
archiveType(readFileSync('foo.zip')); | ||
archiveType(buffer); | ||
//=> {ext: 'zip', mime: 'application/zip'} | ||
@@ -30,15 +29,37 @@ ``` | ||
### archiveType(buf) | ||
### archiveType(input) | ||
Returns [`7z`](https://github.com/kevva/is-7zip), [`bz2`](https://github.com/kevva/is-bzip2), [`gz`](https://github.com/kevva/is-gzip), [`rar`](https://github.com/kevva/is-rar), [`tar`](https://github.com/kevva/is-tar), [`zip`](https://github.com/kevva/is-zip), [`xz`](https://github.com/kevva/is-xz) or `false`. | ||
Returns an `Object` with: | ||
#### buf | ||
- `ext` - One of the [supported file types](#supported-file-types) | ||
- `mime` - The [MIME type](http://en.wikipedia.org/wiki/Internet_media_type) | ||
Type: `buffer` *(Node.js)*, `uint8array` | ||
Or `null` when no match. | ||
It only needs the first 261 bytes. | ||
#### input | ||
Type: `Buffer` `Uint8Array` | ||
It only needs the first 262 bytes. | ||
## Supported file types | ||
- `7z` | ||
- `bz2` | ||
- `gz` | ||
- `rar` | ||
- `tar` | ||
- `zip` | ||
- `xz` | ||
- `gz` | ||
## Related | ||
- [archive-type-cli](https://github.com/kevva/archive-type-cli) - CLI for this module | ||
## License | ||
MIT © [Kevin Mårtensson](https://github.com/kevva) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
63
3132
3
1
+ Addedfile-type@4.4.0(transitive)
- Removedfile-type@3.9.0(transitive)
Updatedfile-type@^4.2.0