What is archive-type?
The archive-type npm package is used to detect the type of archive file based on its buffer. It supports various archive formats such as zip, tar, rar, and more.
What are archive-type's main functionalities?
Detect Archive Type
This feature allows you to detect the type of an archive file by reading its buffer. The code sample reads a file into a buffer and then uses the archiveType function to determine the file type.
const archiveType = require('archive-type');
const fs = require('fs');
const buffer = fs.readFileSync('example.zip');
const type = archiveType(buffer);
console.log(type); // { ext: 'zip', mime: 'application/zip' }
Other packages similar to archive-type
file-type
The file-type package is used to detect the file type of a Buffer/Uint8Array/ArrayBuffer. It supports a wide range of file types, including archives, images, videos, and more. Compared to archive-type, file-type offers broader file type detection capabilities.
detect-file-type
The detect-file-type package is another library for detecting file types from a buffer. It supports various file formats, including archives. While similar to archive-type, it also provides additional functionalities for detecting other file types.
archive-type
Detect the archive type of a Buffer/Uint8Array
Install
$ npm install --save archive-type
Usage
const archiveType = require('archive-type');
const readChunk = require('read-chunk');
const buffer = readChunk.sync('unicorn.zip', 0, 262);
archiveType(buffer);
API
archiveType(input)
Returns an Object
with:
Or null
when no match.
input
Type: Buffer
Uint8Array
It only needs the first 262 bytes.
Supported file types
Related
License
MIT © Kevin Mårtensson