fleep

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 2 Imported by: 1

README

fleep

Go Report Card License PkgGoDev Version

File format determination package for Go

Getting Started

fleep is a package that determines file format by file signature (also known as "magic number").

Installation

You can download the source using go get command:

go get github.com/floyernick/fleep-go

Usage

Main function GetInfo determines file format. It takes file as a byte sequence and returns info about file.

Info has the following fields:

  • Type -> list of suitable file types
  • Extension -> list of suitable file extensions
  • Mime -> list of suitable file MIME types

Also Info has the following methods:

  • TypeMatches -> checks if file type matches with given type as an argument
  • ExtensionMatches -> checks if file extension matches with given extension as an argument
  • MimeMatches -> checks if file MIME type matches with given MIME type as an argument

There is an example (error handling omitted):

package main

import (
	"fleep"
	"fmt"
	"io/ioutil"
)

func main() {
	file, _ := ioutil.ReadFile("gopher.png")        // Reads PNG file
	info, _ := fleep.GetInfo(file)                  // Gets file format
	fmt.Println(info.Type)                          // Prints [raster-image]
	fmt.Println(info.Extension)                     // Prints [png]
	fmt.Println(info.Mime)                          // Prints [image/png]
	fmt.Println(info.TypeMatches(fleep.RasterImage) // Prints true
	fmt.Println(info.ExtensionMatches("jpg"))       // Prints false
	fmt.Println(info.MimeMatches("image/png"))      // Prints true
}

Supported Formats

There is a list of supported formats (in alphabetical order):

Raster Image:

  • BMP
  • GIF
  • ICO
  • JP2
  • JPEG
  • PNG
  • PSD
  • TIFF
  • WEBP

Raw Image:

  • ARW
  • CR2
  • CRW
  • DNG
  • ERF
  • NEF
  • NRW
  • ORF
  • PEF
  • RAF
  • RAW
  • RW2
  • SRW
  • X3F

Vector Image:

  • AI
  • EPS

3D Image:

  • C4D
  • FBX
  • MA
  • MS3D
  • MTL
  • OBJ
  • PLY
  • WRL
  • X3D
  • XSI

Audio:

  • AAC
  • AC3
  • AIFF
  • AMR
  • AU
  • FLAC
  • M4A
  • MIDI
  • MKA
  • MP3
  • OGA
  • RA
  • VOC
  • WAV
  • WMA

Video:

  • 3G2
  • 3GP
  • ASF
  • AVI
  • FLV
  • M4V
  • MKV
  • MOV
  • MP4
  • MPG
  • OGV
  • SWF
  • VOB
  • WEBM
  • WMV

Document:

  • DOC
  • DOCX
  • EPUB
  • KEY
  • NUMBERS
  • ODP
  • ODS
  • ODT
  • PAGES
  • PDF
  • PPS
  • PPT
  • PPTX
  • RTF
  • XLS
  • XLSX
  • XML

Archive:

  • 7Z
  • DMG
  • GZ
  • ISO
  • RAR
  • TAR.Z
  • ZIP

Executable:

  • COM
  • EXE
  • JAR

Font:

  • OTF
  • TTF
  • WOFF
  • WOFF2

System:

  • CAB
  • CAT
  • DLL
  • DRV
  • REG
  • SDB
  • SYS

Database:

  • SQLITE

Contribute

We would be happy to receive your propositions of improvement! Read Contributing Guide for more details.

License

This project is licensed under the MIT License.

Authors

Mykyta Paliienko - GitHub profile

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileType

type FileType int

FileType represents supported file type

const (
	RasterImage FileType
	RawImage
	VectorImage
	ThreeDimensionalImage
	Audio
	Video
	Document
	Archive
	Executable
	Font
	System
	Database
)

type Info

type Info struct {
	Type      []FileType
	Extension []string
	Mime      []string
}

Info represents file info

func GetInfo

func GetInfo(file []byte) (Info, error)

GetInfo returns file info

func (*Info) ExtensionMatches

func (info *Info) ExtensionMatches(value string) bool

ExtensionMatches checks if the file matches provided extension

func (*Info) Is3DImage

func (info *Info) Is3DImage() bool

Is3DImage checks if the file is a 3D image

func (*Info) IsArchive

func (info *Info) IsArchive() bool

IsArchive checks if the file is an archive

func (*Info) IsAudio

func (info *Info) IsAudio() bool

IsAudio checks if the file is an audio

func (*Info) IsDatabase

func (info *Info) IsDatabase() bool

IsDatabase checks if the file is a database

func (*Info) IsDocument

func (info *Info) IsDocument() bool

IsDocument checks if the file is a document

func (*Info) IsExecutable

func (info *Info) IsExecutable() bool

IsExecutable checks if the file is an executable

func (*Info) IsFont

func (info *Info) IsFont() bool

IsFont checks if the file is a font

func (*Info) IsRasterImage

func (info *Info) IsRasterImage() bool

IsRasterImage checks if the file is a raster image

func (*Info) IsRawImage

func (info *Info) IsRawImage() bool

IsRawImage checks if the file is a raw image

func (*Info) IsSystem

func (info *Info) IsSystem() bool

IsSystem checks if the file is a system

func (*Info) IsVectorImage

func (info *Info) IsVectorImage() bool

IsVectorImage checks if the file is a vector image

func (*Info) IsVideo

func (info *Info) IsVideo() bool

IsVideo checks if the file is a video

func (*Info) MimeMatches

func (info *Info) MimeMatches(value string) bool

MimeMatches checks if the file matches provided MIME type

func (*Info) TypeMatches

func (info *Info) TypeMatches(value FileType) bool

TypeMatches checks if the file matches provided file type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL