Socket
Socket
Sign inDemoInstall

archive-type

Package Overview
Dependencies
1
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc