New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

type-teller

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-teller

Detect the file type of a Buffer/Uint8Array/ArrayBuffer

latest
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Type-teller

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

This package is for detecting binary-based file formats

Installation

npm install type-teller

Usage

// javascript
const { detectFileType } = require("type-teller");
// typescript
import { detectFileType } from "type-teller";
//
const pathToFile = "./myImage.png";
const buffer = fs.readFileSync(pathToFile);
const type = detectFileType(buffer);
console.log(type); // Outputs: { ext: 'png' mime: 'image/png' }

Determine file type from extension:

This is NOT recommended for critical applications. This method assumes that the file extension matches the actual file type. This only checks the file extension.

// javascript
const { fileTypeFromFile } = require("type-teller");
// typescript
import { fileTypeFromFile } from "type-teller";

const pathToFile = "./myVideo.mp4";
const type = fileTypeFromFile();
console.log(type); // Outputs: { ext: 'mp4', mime: 'video/mp4' }

Supported file types:

  • png
  • jpeg
  • gif
  • zip
  • pdf
  • bmp
  • avif
  • mp4
  • avi
  • mkv
  • wmv
  • flv
  • webm
  • mp3
  • wav
  • flac
  • OGG & OGA
  • wma
  • tiff
  • rar
  • 7-zip
  • SQLite
  • ICO
  • GZIP
  • TAR
  • PSD
  • RTF
  • XML
  • DOC
  • XLS
  • PPT
  • XLSX
  • PPTX
  • AVI
  • MIDI
  • WEBP
  • SWF
  • PSD

Keywords

filetype

FAQs

Package last updated on 14 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts