1.0.8 • Published 8 months ago

type-teller v1.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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