Skip to content

Small and dependency free Nim package to infer file and MIME type checking the magic numbers signature.

License

Notifications You must be signed in to change notification settings

jiro4989/filetype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

filetype

gh-actions

Small and dependency free Nim package to infer file and MIME type checking the magic numbers signature. filetype is heavily inspired by h2non/filetype.

import filetype
let content = readFile("tests/testdata/sample.png")
doAssert match(content).extension == "png"
doAssert matchFile("tests/testdata/sample.png").mime.value == "image/png"
doAssert isPngFile("tests/testdata/sample.png")
if isZipFile("tests/testdata/sample.zip"):
  echo "file is zip"
type
   FileType* = object
      mime*: Mime
      extension*: string ## File extension. (ex: `zip`)
   Mime* = object
      ## MIME type.
      typ*: string     ## Ex: `application` of `application/gzip`.
      subType*: string ## Ex: `gzip` of `application/gzip`.
      value*: string   ## Ex: `application/gzip` of `application/gzip`.

See filetype module.

$ nimble install -Y filetype
Type Format
Image jpeg, jp2, png, gif, webp, cr2, tiff, bmp, jxr, psd, ico, dwg
Archive gz, zip, bz2, 7z, pdf, exe, rtf, nes, crx, ps, xz, sqlite, deb, ar, lz, rpm, elf
Audio midi, ogg, flac, wav, amr, mp3, aac
Font woff, woff2, ttf, otf
Video wmv, flv, avi, mpeg, mp4

MIT