1.0.20 • Published 9 months ago

get-typeandmime v1.0.20

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

get-typeandmime

Detect the File type of a Buffer/Uint8Array/ArrayBuffer

The file type is detected by checking the magic number of the buffer.

This package is for detecting binary-based file formats, not text-based formats like .txt, .csv, .svg, etc.

Install

npm i get-typeandmime

This package is a ES5 module package.But can be used with both ES5 and ES6 as well

Usage

Node.js

Determine file type from a file:

const {getFileType} = require("get-typeandmime")
const file = "../.path/file.extension"

console.log(getFileType(file));

Determine file type from a Buffer, which may be a portion of the beginning of a file:

This can also be used to read from a remote location:

const {getStreamFileType} = require("get-typeandmime")

const remoteFile = "https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg";
(async()=>{
    console.log("Remote File Type:",await getStreamFileType(remoteFile));

})()

Or Unsupported file type when there is no match.

buffer

Type: Buffer | Uint8Array | ArrayBuffer

A buffer representing file data. It works best if the buffer contains the entire file. It may work with a smaller portion as well.

filePath

file: string

The file path to parse.

Contributions

Pull requests are welcome for additional commonly used file types.

Maintainers

1.0.20

9 months ago

1.0.19

9 months ago

1.0.18

10 months ago

1.0.17

10 months ago

1.0.16

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.10

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago