0.4.6 • Published 5 months ago

file-type-mime v0.4.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

file-type-mime

FOSSA Status

Utility to parse mime type from a file content.

Usage

Browser (react)

import { parse } from 'file-type-mime';

export default function fileUpload() {
  async function onChange(e) {
    const [file] = e.target.files;
    const buffer = await file.arrayBuffer();
    const result = parse(buffer);

    console.log('MIME_TYPE', result);
  }

  return (
    <form>
      <input type="file" onChange={onChange}>
    </form>
  );
}

Node.js

import { parse } from "file-type-mime";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";

const file = resolve("./path/to/file.pdf");
const buffer = readFileSync(file);
const result = parse(buffer);

console.log("MIME_TYPE", result);

API

Signature

function parse(buffer: ArrayBuffer, options: Options = {}): Result | undefined

Arguments

buffer

Type: ArrayBuffer

A buffer representing file data

options (optional)

Type: { extra?: boolean; hint?: { ext?: string; mime?: string } }

  • hint - used to short-circuit general flow by filtering signatures list
  • extra - used to parse additional file type formats (like json, txt)

Return

Type: { ext: string; mime: string } | undefined

Supported file types

(more to come...)

File extensionContent (mime) type
bmpimage/bmp
gifimage/gif
icoimage/x-icon
jpgimage/jpeg
heicimage/heic
pngimage/png
tiffimage/tiff
pdfapplication/pdf
rtfapplication/rtf
epubapplication/epub+zip
gzapplication/gzip
jarapplication/java-archive
zipapplication/zip
bz2application/x-bzip2
rarapplication/x-rar-compressed
tarapplication/x-tar
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
opdapplication/vnd.oasis.opendocument.presentation
odsapplication/vnd.oasis.opendocument.spreadsheet
odtapplication/vnd.oasis.opendocument.text
dbapplication/vnd.sqlite3
7zapplication/x-7z-compressed
avivideo/x-msvideo
mp3audio/mp3
mp4video/mp4
ogaaudio/ogg
oggaudio/ogg
ogmvideo/ogg
ogvvideo/ogg
ogxapplication/ogg
wavaudio/wav
wofffont/woff
woff2font/woff2
debapplication/x-deb
flacaudio/x-flac
psdimage/vnd.adobe.photoshop
wasmapplication/wasm
webpimage/webp
classapplication/java-vm
exeapplication/x-msdownload
parquetapplication/vnd.apache.parquet
jsonapplication/json
txttext/plain
vsixapplication/vsix
movvideo/quicktime
afivimage/avif
m4vvideo/x-m4v

License

FOSSA Status

0.4.6

5 months ago

0.4.5

8 months ago

0.4.4

8 months ago

0.4.3

11 months ago

0.4.1

11 months ago

0.4.0

1 year ago

0.4.2

11 months ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.6

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.5

1 year ago

0.3.2

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.0.10

2 years ago

0.1.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago