Giter VIP home page Giter VIP logo

filetypes.jl's Introduction

FileTypes.jl

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

Build Status Coverage

Features

  • Supports a wide range of file types
  • Provides file extension and proper MIME type
  • File discovery by extension or MIME type
  • File discovery by class (image, video, audio...)
  • Provides a bunch of helpers and file matching shortcuts
  • Simple and semantic API

General Info

currently under developement.

Take a look on contribution

Examples

Simple file type checking

  using FileTypes

  julia> kind = matcher("example.gif")
  FileType.Types("gif", "image/gif")

  julia> kind.extension
  "gif"

  julia> kind.mime
  "image/gif"

Check type class

  using FileTypes
  julia> Is(FileType.Image,"example.gif")
  true

additional checker function

  using FileTypes

  julia> is_mime_supported("image/jpeg")
  true

  julia> is_extension_supported("png")
  true

You can see the supported file type using

  julia> using FileTypes

  julia> FileType
  FileTypes.FileType

  julia> FileType.Image
  Dict{FileTypes.FileType.Type, Function} with 12 entries:
    Type("gif", MIME type image/gif)                 => Gif
    Type("cr2", MIME type image/x-canon-cr2)         => CR2
    Type("jp2", MIME type image/jp2)                 => Jpeg2000
    Type("psd", MIME type image/vnd.adobe.photoshop) => Psd
    Type("bmp", MIME type image/bmp)                 => Bmp
    Type("tif", MIME type image/tiff)                => Tiff
    Type("jpg", MIME type image/jpeg)                => Jpeg
    Type("ico", MIME type image/vnd.microsoft.icon)  => Ico
    Type("png", MIME type image/png)                 => Png
    Type("webp", MIME type image/webp)               => Webp
    Type("jxr", MIME type image/vnd.ms-photo)        => Jxr
    Type("dwg", MIME type image/vnd.dwg)             => Dwg

Supported types

Image

  • jpg - image/jpeg
  • png - image/png
  • gif - image/gif
  • webp - image/webp
  • cr2 - image/x-canon-cr2
  • tif - image/tiff
  • bmp - image/bmp
  • heif - image/heif
  • jxr - image/vnd.ms-photo
  • psd - image/vnd.adobe.photoshop
  • ico - image/vnd.microsoft.icon
  • dwg - image/vnd.dwg

Video

  • m4v - video/x-m4v
  • webm - video/webm
  • mov - video/quicktime
  • avi - video/x-msvideo
  • wmv - video/x-ms-wmv
  • mpg - video/mpeg
  • flv - video/x-flv
  • 3gp - video/3gpp

Audio

  • mid - audio/midi
  • mp3 - audio/mpeg
  • m4a - audio/m4a
  • ogg - audio/ogg
  • flac - audio/x-flac
  • wav - audio/x-wav
  • amr - audio/amr
  • aac - audio/aac

Archive

  • epub - application/epub+zip
  • zip - application/zip
  • tar - application/x-tar
  • rar - application/vnd.rar
  • gz - application/gzip
  • bz2 - application/x-bzip2
  • 7z - application/x-7z-compressed
  • xz - application/x-xz
  • pdf - application/pdf
  • exe - application/vnd.microsoft.portable-executable
  • swf - application/x-shockwave-flash
  • rtf - application/rtf
  • iso - application/x-iso9660-image
  • eot - application/octet-stream
  • ps - application/postscript
  • sqlite - application/vnd.sqlite3
  • nes - application/x-nintendo-nes-rom
  • crx - application/x-google-chrome-extension
  • cab - application/vnd.ms-cab-compressed
  • deb - application/vnd.debian.binary-package
  • ar - application/x-unix-archive
  • Z - application/x-compress
  • lz - application/x-lzip
  • rpm - application/x-rpm
  • elf - application/x-executable
  • dcm - application/dicom

Documents

  • doc - application/msword
  • xls - application/vnd.ms-excel
  • ppt - application/vnd.ms-powerpoint

Font

  • woff - application/font-woff
  • woff2 - application/font-woff
  • ttf - application/font-sfnt
  • otf - application/font-sfnt

Application

  • wasm - application/wasm
  • dex - application/vnd.android.dex
  • dey - application/vnd.android.dey

Contribution

  • Currently, the Is API takes a parameter as FileType.Images.Image which is a dictionary of all the supported image. I think it should be an (immutable)namedtuple as the custom filetype should be of unknown type only.
  • There should be an API to add new custom Types.
  • Currently, Filetypes(publicly accessed) is a tuple that should be an Array as this library has to provide an API to add a new type, and that new type could we handled in Is API like FileType.Unknown.
  • The FileType.Images.Image should be FileType.Images

Benchmark

system info: SMP Debian 5.8.7-1kali1 (2020-09-14) x86_64 GNU/Linux Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz

julia> @benchmark matcher("example.png")
BenchmarkTools.Trial: 
  memory estimate:  1.69 KiB
  allocs estimate:  16
  --------------
  minimum time:     12.304 μs (0.00% GC)
  median time:      12.859 μs (0.00% GC)
  mean time:        14.708 μs (0.00% GC)
  maximum time:     329.586 μs (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1

License

MIT - Prince Roshan

filetypes.jl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

filetypes.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.