magic

package module
v0.0.0-...-744ef23 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2017 License: MIT Imports: 2 Imported by: 0

README

GoDoc MarkMueller MarkMueller

magic

Overview

Package magic will determine the type of file based on the first "magic bytes". The file signatures are not complete, but represent some of the most common file types.

Index

Examples
Package files

file_signatures.go magic.go

type FileInfo

type FileInfo struct {

    // Name of the file
    Name string

    // Comma delimited list of known extensions for this file type
    Ext []string

    // Description of the file
    Description string

    // Size of the file in bytes
    Size int64
}

FileInfo struct

func FileBytes
func FileBytes(file string) (FileInfo, error)

FileBytes returns a FileInfo struct. The error will be non-nil if the file type cannot be determined or if the file cannot be read.


Generated by godoc2md

Documentation

Overview

Package magic will determine the type of file based on the first "magic bytes". The file signatures are not complete, but represent some of the most common file types.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {

	// Name of the file
	Name string

	// Comma delimited list of known extensions for this file type
	Ext []string

	// Description of the file
	Description string

	// Size of the file in bytes
	Size int64
}

FileInfo struct

func FileBytes

func FileBytes(file string) (FileInfo, error)

FileBytes returns a FileInfo struct. The error will be non-nil if the file type cannot be determined or if the file cannot be read.

Example

Example FileBytes

// Create a tiny GIF image file
fi, err := magic.FileBytes(tiniestGifEver)
if err == nil {
	fmt.Printf("The file type is %s", fi.Description)
}
Output:

The file type is GIF89a Image

Jump to

Keyboard shortcuts

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