fs

package
v0.0.0-...-f83a9f7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package fs provides filesystem related constants and functions.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const (
	PPIgnoreFilename  = ".ppignore"
	PPIgnoreAll       = "*"
	PPStorageFilename = ".ppstorage"
	PPHiddenPathname  = ".photoprism"
)
View Source
const (
	ExtJPEG = ".jpg"
	ExtPNG  = ".png"
	ExtDNG  = ".dng"
	ExtTHM  = ".thm"
	ExtAVC  = ".avc"
	ExtHEVC = ".hevc"
	ExtMP4  = ".mp4"
	ExtMOV  = ".mov"
	ExtYAML = ".yml"
)
View Source
const (
	PathSeparator = string(filepath.Separator)
	Home          = "~"
	HomePath      = Home + PathSeparator
)
View Source
const (
	MimeTypeUnknown = ""
	MimeTypeBinary  = "application/octet-stream"
	MimeTypeJPEG    = "image/jpeg"
	MimeTypeJPEGXL  = "image/jxl"
	MimeTypePNG     = "image/png"
	MimeTypeAPNG    = "image/vnd.mozilla.apng"
	MimeTypeGIF     = "image/gif"
	MimeTypeBMP     = "image/bmp"
	MimeTypeTIFF    = "image/tiff"
	MimeTypeDNG     = "image/dng"
	MimeTypeAVIF    = "image/avif"
	MimeTypeAVIFS   = "image/avif-sequence"
	MimeTypeHEIC    = "image/heic"
	MimeTypeHEICS   = "image/heic-sequence"
	MimeTypeWebP    = "image/webp"
	MimeTypeMP4     = "video/mp4"
	MimeTypeMOV     = "video/quicktime"
	MimeTypeSVG     = "image/svg+xml"
	MimeTypeAI      = "application/vnd.adobe.illustrator"
	MimeTypePS      = "application/postscript"
	MimeTypeEPS     = "image/eps"
	MimeTypeXML     = "text/xml"
	MimeTypeJSON    = "application/json"
)

Variables

View Source
var (
	ModeDir  os.FileMode = 0o777
	ModeFile os.FileMode = 0o666
)
View Source
var AssetPaths = []string{
	"/opt/photoprism/assets",
	"/photoprism/assets",
	"~/.photoprism/assets",
	"~/photoprism/assets",
	"photoprism/assets",
	"assets",
	"/var/lib/photoprism/assets",
}
View Source
var DscNameRegexp = regexp.MustCompile("\\D{3}[\\d_]\\d{4,8}_?\\d{0,6}_?\\d{0,6}[\\.jpgJPGXx]{0,4}")
View Source
var Extensions = FileExtensions{}/* 123 elements not displayed */

Extensions contains the filename extensions of file formats known to PhotoPrism.

View Source
var FileTypes = Extensions.Types(ignoreCase)

FileTypes contains the default file type extensions.

View Source
var ImportPaths = []string{
	"/photoprism/storage/media/import",
	"/photoprism/media/import",
	"/photoprism/import",
	"/srv/photoprism/storage/media/import",
	"/srv/photoprism/media/import",
	"/srv/photoprism/import",
	"/opt/photoprism/storage/media/import",
	"/opt/photoprism/media/import",
	"/opt/photoprism/import",
	"/media/import",
	"/storage/import",
	"/import",
	"media/import",
	"storage/import",
	"photoprism/import",
	"PhotoPrism/Import",
	"pictures/import",
	"Pictures/Import",
	"photos/import",
	"Photos/Import",
	"import",
	"Import",
	"~/pictures/import",
	"~/Pictures/Import",
	"~/photoprism/import",
	"~/PhotoPrism/Import",
	"~/photos/import",
	"~/Photos/Import",
	"~/import",
	"~/Import",
	"/var/lib/photoprism/import",
}
View Source
var OriginalPaths = []string{
	"/photoprism/storage/media/originals",
	"/photoprism/media/originals",
	"/photoprism/originals",
	"/srv/photoprism/storage/media/originals",
	"/srv/photoprism/media/originals",
	"/srv/photoprism/originals",
	"/opt/photoprism/storage/media/originals",
	"/opt/photoprism/media/originals",
	"/opt/photoprism/originals",
	"/media/originals",
	"/storage/originals",
	"/originals",
	"media/originals",
	"storage/originals",
	"photoprism/originals",
	"PhotoPrism/Originals",
	"photoprism/original",
	"PhotoPrism/Original",
	"pictures/originals",
	"Pictures/Originals",
	"pictures/original",
	"Pictures/Original",
	"photos/originals",
	"Photos/Originals",
	"photos/original",
	"Photos/Original",
	"originals",
	"Originals",
	"original",
	"Original",
	"pictures",
	"Pictures",
	"photos",
	"Photos",
	"images",
	"Images",
	"bilder",
	"Bilder",
	"fotos",
	"Fotos",
	"~/photoprism/originals",
	"~/PhotoPrism/Originals",
	"~/photoprism/original",
	"~/PhotoPrism/Original",
	"~/pictures/originals",
	"~/Pictures/Originals",
	"~/pictures/original",
	"~/Pictures/Original",
	"~/photos/originals",
	"~/Photos/Originals",
	"~/photos/original",
	"~/Photos/Original",
	"~/pictures",
	"~/Pictures",
	"~/photos",
	"~/Photos",
	"~/images",
	"~/Images",
	"~/bilder",
	"~/Bilder",
	"~/fotos",
	"~/Fotos",
	"/var/lib/photoprism/originals",
}
View Source
var TypeAnimated = TypeMap{
	ImageGIF:   MimeTypeGIF,
	ImagePNG:   MimeTypeAPNG,
	ImageWebP:  MimeTypeWebP,
	ImageAVIF:  MimeTypeAVIFS,
	ImageAVIFS: MimeTypeAVIFS,
	ImageHEIC:  MimeTypeHEICS,
	ImageHEICS: MimeTypeHEICS,
}

TypeAnimated maps animated file types to their mime type.

View Source
var TypeInfo = TypeMap{
	ImageRaw:        "Unprocessed Sensor Data",
	ImageDNG:        "Adobe Digital Negative",
	ImageJPEG:       "Joint Photographic Experts Group (JPEG)",
	ImageJPEGXL:     "JPEG XL",
	ImagePNG:        "Portable Network Graphics",
	ImageGIF:        "Graphics Interchange Format",
	ImageTIFF:       "Tag Image File Format",
	ImagePSD:        "Adobe Photoshop",
	ImageBMP:        "Bitmap",
	ImageMPO:        "Stereoscopic JPEG (3D)",
	ImageAVIF:       "AV1 Image File Format",
	ImageAVIFS:      "AV1 Image Sequence",
	ImageHEIF:       "High Efficiency Image File Format",
	ImageHEIC:       "High Efficiency Image Container",
	ImageHEICS:      "HEIC Image Sequence",
	ImageWebP:       "Google WebP",
	VideoWebM:       "Google WebM",
	VideoMP2:        "MPEG 2 (H.262)",
	VideoAVC:        "Advanced Video Coding (H.264, MPEG-4 Part 10)",
	VideoHEVC:       "High Efficiency Video Coding (H.265)",
	VideoVVC:        "Versatile Video Coding (H.266)",
	VideoAV1:        "AOMedia Video 1",
	VideoMOV:        "Apple QuickTime",
	VideoMP4:        "Multimedia Container (MPEG-4 Part 14)",
	VideoM4V:        "Apple iTunes Multimedia Container",
	VideoMXF:        "Material Exchange Format",
	VideoAVI:        "Microsoft Audio Video Interleave",
	VideoASF:        "Advanced Systems Format ",
	VideoWMV:        "Windows Media",
	VideoDV:         "DV Video",
	Video3GP:        "Mobile Multimedia Container (3G)",
	Video3G2:        "Mobile Multimedia Container (CDMA2000)",
	VideoFlash:      "Adobe Flash",
	VideoMKV:        "Matroska Multimedia Container",
	VideoMPG:        "Moving Picture Experts Group (MPEG)",
	VideoMJPG:       "Motion JPEG",
	VideoAVCHD:      "Advanced Video Coding High Definition (AVCHD)",
	VideoBDAV:       "Blu-ray MPEG-2 Transport Stream",
	VideoOGV:        "Ogg Media (OGG)",
	VectorSVG:       "Scalable Vector Graphics",
	VectorAI:        "Adobe Illustrator",
	VectorPS:        "Adobe PostScript",
	VectorEPS:       "Encapsulated PostScript",
	SidecarXMP:      "Adobe Extensible Metadata Platform",
	SidecarAAE:      "Apple Image Edits XML",
	SidecarXML:      "Extensible Markup Language",
	SidecarJSON:     "Serialized JSON Data (Exiftool, Google Photos)",
	SidecarYAML:     "Serialized YAML Data (Config, Metadata)",
	SidecarText:     "Plain Text",
	SidecarInfo:     "Info Text",
	SidecarMarkdown: "Markdown Formatted Text",
	TypeUnknown:     "Other",
}

TypeInfo contains human-readable descriptions for supported file formats

View Source
var UUIDNameRegexp = regexp.MustCompile("[A-Fa-f0-9\\-]{16,36}_?[A-Za-z0-9_]{0,20}") // Example: 8263987746_d0a6055c58_o
View Source
var UniqueNameRegexp = regexp.MustCompile("[a-f0-9]{8,16}_[a-f0-9]{6,16}_[A-Za-z0-9]{1,20}_?[A-Za-z0-9]{0,4}") // Example: 8263987746_d0a6055c58_o

Functions

func Abs

func Abs(name string) string

Abs returns the full path of a file or directory, "~" is replaced with home.

func AbsPrefix

func AbsPrefix(fileName string, stripSequence bool) string

AbsPrefix returns the directory and base filename without any extensions.

func AddToZip

func AddToZip(zipWriter *zip.Writer, filename string) error

func BasePrefix

func BasePrefix(fileName string, stripSequence bool) string

BasePrefix returns the filename base without any extensions and path.

func CacheFileFromReader

func CacheFileFromReader(fileName string, reader io.Reader) (string, error)

CacheFileFromReader writes data from an io.Reader to a file with the specified name if it does not exist. If the path does not exist or the file cannot be written, an error is returned. No error is returned if the file already exists.

func CachePath

func CachePath(basePath, fileHash, namespace string, create bool) (cachePath string, err error)

CachePath returns a cache directory name based on the base path, file hash and cache namespace.

func CanonicalName

func CanonicalName(date time.Time, checksum string) string

CanonicalName returns a canonical name based on time and CRC32 checksum.

func CaseInsensitive

func CaseInsensitive(storagePath string) (result bool, err error)

CaseInsensitive tests if a storage path is case-insensitive.

func Checksum

func Checksum(fileName string) string

Checksum returns the CRC32 checksum of a file as string.

func Copy

func Copy(src, dest string) (err error)

Copy copies a file to a destination.

func DirIsEmpty

func DirIsEmpty(path string) bool

DirIsEmpty returns true if a directory is empty.

func Dirs

func Dirs(root string, recursive bool, followLinks bool) (result []string, err error)

Dirs returns a slice of directories in a path, optional recursively and with symlinks.

Warning: Following symlinks can make the result non-deterministic and hard to test!

func Download

func Download(fileName string, url string) error

Download downloads a file from a URL.

func Ext

func Ext(name string) string

Ext returns all extension of a file name including the dots.

func FileExists

func FileExists(fileName string) bool

FileExists returns true if file exists and is not a directory.

func FileExistsNotEmpty

func FileExistsNotEmpty(fileName string) bool

FileExistsNotEmpty returns true if file exists, is not a directory, and not empty.

func FileName

func FileName(fileName, dirName, baseDir, fileExt string) string

FileName returns the relative filename with the same base and a given extension in a directory.

func FileNameHidden

func FileNameHidden(name string) bool

FileNameHidden tests is a file name belongs to a hidden file.

func FindDir

func FindDir(dirs []string) string

FindDir checks if any of the specified directories exist and returns the absolute path of the first directory found.

func Hash

func Hash(fileName string) string

Hash returns the SHA1 hash of a file as string.

func IgnoreCase

func IgnoreCase()

IgnoreCase enables the case-insensitive mode.

func IsAnimatedImage

func IsAnimatedImage(fileName string) bool

IsAnimatedImage checks if the type associated with the specified filename may be animated.

func IsAsciiID

func IsAsciiID(s string) bool

IsAsciiID tests if the string is a file name that only contains uppercase ascii letters and numbers like "IQVG4929".

func IsCanonical

func IsCanonical(basename string) bool

IsCanonical returns true if the file basename is canonical.

func IsDscName

func IsDscName(s string) bool

IsDscName tests if the string looks like a file name generated by a camera.

func IsGenerated

func IsGenerated(fileName string) bool

IsGenerated tests if the file name looks like an automatically generated identifier.

func IsHash

func IsHash(s string) bool

IsHash tests if a string looks like a hash.

func IsInt

func IsInt(s string) bool

IsInt tests if the file base is an integer number.

func IsUniqueName

func IsUniqueName(s string) bool

IsUniqueName tests if the string looks like a unique file name.

func LowerExt

func LowerExt(fileName string) string

LowerExt returns the file name extension with dot in lower case.

func MimeType

func MimeType(filename string) (mimeType string)

MimeType returns the mime type of a file, or an empty string if it could not be detected.

func MkdirAll

func MkdirAll(dir string) error

MkdirAll creates a directory including all parent directories that might not yet exist. No error is returned if the directory already exists.

func ModTime

func ModTime(filePath string) time.Time

ModTime returns the last modification time of a file or directory in UTC.

func Move

func Move(src, dest string) (err error)

Move moves an existing file to a new destination and returns an error if it fails.

func NonCanonical

func NonCanonical(basename string) bool

NonCanonical returns true if the file basename is NOT canonical.

func NormalizedExt

func NormalizedExt(fileName string) string

NormalizedExt returns the file extension without dot and in lowercase.

func PathExists

func PathExists(path string) bool

PathExists tests if a path exists, and is a directory or symlink.

func PathWritable

func PathWritable(path string) bool

PathWritable tests if a path exists and is writable.

func ReadLines

func ReadLines(fileName string) (lines []string, err error)

ReadLines returns all lines in a text file as string slice.

func RelName

func RelName(fileName, dir string) string

RelName returns the file name relative to a directory.

func RelPrefix

func RelPrefix(fileName, dir string, stripSequence bool) string

RelPrefix returns the relative filename.

func Resolve

func Resolve(filePath string) (string, error)

Resolve returns the absolute file path, with all symlinks resolved.

func SkipWalk

func SkipWalk(fileName string, isDir, isSymlink bool, done Done, ignore *IgnoreList) (skip bool, result error)

SkipWalk returns true if the file or directory should be skipped in godirwalk.Walk()

func StripExt

func StripExt(name string) string

StripExt removes the file type extension from a file name (if any).

func StripKnownExt

func StripKnownExt(name string) string

StripKnownExt removes all known file type extension from a file name (if any).

func StripSequence

func StripSequence(fileName string) string

StripSequence removes common sequence patterns at the end of file names.

func SymlinksSupported

func SymlinksSupported(storagePath string) (bool, error)

SymlinksSupported tests if a storage path supports symlinks.

func TrimExt

func TrimExt(ext string) string

TrimExt removes unwanted characters from file extension strings, and makes it lowercase for comparison.

func Unzip

func Unzip(src, dest string) (fileNames []string, err error)

Extract Zip file in destination directory

func Writable

func Writable(path string) bool

Writable checks if the path is accessible for reading and writing.

func WriteFile

func WriteFile(fileName string, data []byte) error

WriteFile overwrites a file with the specified bytes as content. If the path does not exist or the file cannot be written, an error is returned.

func WriteFileFromReader

func WriteFileFromReader(fileName string, reader io.Reader) (err error)

WriteFileFromReader writes data from an io.Reader to a newly created file with the specified name. If the path does not exist or the file cannot be written, an error is returned.

func WriteString

func WriteString(fileName string, s string) error

WriteString overwrites a file with the specified string as content. If the path does not exist or the file cannot be written, an error is returned.

func WriteUnixTime

func WriteUnixTime(fileName string) (unixTime int64, err error)

WriteUnixTime overwrites a file with the current Unix timestamp as content. If the path does not exist or the file cannot be written, an error is returned.

func Zip

func Zip(filename string, files []string) error

ZipFiles compresses one or many files into a single zip archive file. Param 1: filename is the output zip file's name. Param 2: files is a list of files to add to the zip.

Types

type Blacklist

type Blacklist map[string]bool

Blacklist represents a file extension blacklist.

func NewBlacklist

func NewBlacklist(extensions string) Blacklist

NewBlacklist creates and initializes a file extension blacklist.

func (Blacklist) Add

func (b Blacklist) Add(ext string)

Add adds a file extension to the blacklist.

func (Blacklist) Allow

func (b Blacklist) Allow(ext string) bool

Allow tests if a file extension is NOT blacklisted.

func (Blacklist) Contains

func (b Blacklist) Contains(ext string) bool

Contains tests if a file extension is blacklisted.

func (Blacklist) Set

func (b Blacklist) Set(extensions string)

Set initializes the blacklist with a list of file extensions.

type Blacklists

type Blacklists map[string]Blacklist

Blacklists represents multiple blacklists.

func NewBlacklists

func NewBlacklists() Blacklists

NewBlacklists creates and initializes file extension blacklists.

type Done

type Done map[string]Status

type FileExtensions

type FileExtensions map[string]Type

FileExtensions maps file extensions to standard formats

func (FileExtensions) Known

func (m FileExtensions) Known(name string) bool

Known tests if the file extension is known (supported).

func (FileExtensions) Types

func (m FileExtensions) Types(noUppercase bool) TypesExt

Types returns known extensions by file type.

type FileInfo

type FileInfo struct {
	Name string    `json:"name"`
	Abs  string    `json:"abs"`
	Size int64     `json:"size"`
	Date time.Time `json:"date"`
	Dir  bool      `json:"dir"`
}

FileInfo represents a file system entry.

func NewFileInfo

func NewFileInfo(file os.FileInfo, dir string) FileInfo

NewFileInfo creates a FileInfo struct from the os.FileInfo record.

func WebFileInfo

func WebFileInfo(file webdav.FileInfo, dir string) FileInfo

WebFileInfo creates a FileInfo struct from a webdav.FileInfo record.

type FileInfos

type FileInfos []FileInfo

func NewFileInfos

func NewFileInfos(infos []os.FileInfo, dir string) FileInfos

func (FileInfos) Abs

func (infos FileInfos) Abs() (result []string)

func (FileInfos) Len

func (infos FileInfos) Len() int

func (FileInfos) Less

func (infos FileInfos) Less(i, j int) bool

func (FileInfos) Swap

func (infos FileInfos) Swap(i, j int)

type IgnoreItem

type IgnoreItem struct {
	Dir     string
	Pattern string
}

IgnoreItem represents a file name pattern to be ignored.

func NewIgnoreItem

func NewIgnoreItem(dir, pattern string, caseSensitive bool) IgnoreItem

NewIgnoreItem returns a pointer to a new IgnoreItem instance.

func (IgnoreItem) Ignore

func (i IgnoreItem) Ignore(dir, base string) bool

Ignore returns true if the file name "base" in the directory "dir" should be ignored.

type IgnoreList

type IgnoreList struct {
	Log IgnoreLogFunc
	// contains filtered or unexported fields
}

IgnoreList represents a list of name patterns to be ignored.

func NewIgnoreList

func NewIgnoreList(configFile string, ignoreHidden bool, caseSensitive bool) *IgnoreList

NewIgnoreList returns a pointer to a new IgnoreList instance.

func (*IgnoreList) AppendItems

func (l *IgnoreList) AppendItems(dir string, patterns []string) error

AppendItems adds items to the list of ignored items.

func (*IgnoreList) ConfigFile

func (l *IgnoreList) ConfigFile(fileName string) error

ConfigFile adds items in fileName to the list of ignored items.

func (*IgnoreList) Dir

func (l *IgnoreList) Dir(dir string) error

Dir adds the ignore file in dirName to the list of ignored items.

func (*IgnoreList) Hidden

func (l *IgnoreList) Hidden() []string

Hidden returns hidden files that were ignored.

func (*IgnoreList) Ignore

func (l *IgnoreList) Ignore(fileName string) bool

Ignore returns true if the file name should be ignored.

func (*IgnoreList) Ignored

func (l *IgnoreList) Ignored() []string

Ignored returns files that were ignored in addition to hidden files.

func (*IgnoreList) Reset

func (l *IgnoreList) Reset()

Reset resets ignored and hidden files.

type IgnoreLogFunc

type IgnoreLogFunc func(fileName string)

type Status

type Status int8
const (
	Found     Status = 1
	Processed Status = 2
)

func (Status) Exists

func (s Status) Exists() bool

func (Status) Processed

func (s Status) Processed() bool

type Type

type Type string

Type represents a file format type.

const (
	ImageRaw Type = "raw" // RAW Image
	ImageDNG Type = "dng" // Adobe Digital Negative
)

Supported media.Raw file types:

const (
	ImageJPEG   Type = "jpg"   // JPEG Image
	ImageJPEGXL Type = "jxl"   // JPEG XL Image
	ImagePNG    Type = "png"   // PNG Image
	ImageGIF    Type = "gif"   // GIF Image
	ImageTIFF   Type = "tiff"  // TIFF Image
	ImagePSD    Type = "psd"   // Adobe Photoshop
	ImageBMP    Type = "bmp"   // BMP Image
	ImageMPO    Type = "mpo"   // Stereoscopic Image that consists of two JPG images that are combined into one 3D image
	ImageAVIF   Type = "avif"  // AV1 Image File (AVIF)
	ImageAVIFS  Type = "avifs" // AV1 Image Sequence (Animated AVIF)
	ImageHEIF   Type = "heif"  // High Efficiency Image File Format (HEIF)
	ImageHEIC   Type = "heic"  // High Efficiency Image Container (HEIC)
	ImageHEICS  Type = "heics" // HEIC Image Sequence
	ImageWebP   Type = "webp"  // Google WebP Image
)

Supported media.Image file types:

const (
	VideoWebM  Type = "webm" // Google WebM Video
	VideoHEVC  Type = "hevc" // H.265, High Efficiency Video Coding (HEVC)
	VideoAVI   Type = "avi"  // Microsoft Audio Video Interleave (AVI)
	VideoAVC   Type = "avc"  // H.264, Advanced Video Coding (AVC, MPEG-4 Part 10)
	VideoVVC   Type = "vvc"  // H.266, Versatile Video Coding (VVC)
	VideoAV1   Type = "av1"  // Alliance for Open Media Video
	VideoMPG   Type = "mpg"  // Moving Picture Experts Group (MPEG)
	VideoMJPG  Type = "mjpg" // Motion JPEG (M-JPEG)
	VideoMP2   Type = "mp2"  // MPEG-2, H.222/H.262
	VideoMP4   Type = "mp4"  // MPEG-4 Container based on QuickTime, can contain AVC, HEVC,...
	VideoM4V   Type = "m4v"  // Apple iTunes MPEG-4 Container, optionally with DRM copy protection
	VideoMKV   Type = "mkv"  // Matroska Multimedia Container, free and open
	VideoMOV   Type = "mov"  // QuickTime File Format, can contain AVC, HEVC,...
	VideoMXF   Type = "mxf"  // Material Exchange Format
	Video3GP   Type = "3gp"  // Mobile Multimedia Container, MPEG-4 Part 12
	Video3G2   Type = "3g2"  // Similar to 3GP, consumes less space & bandwidth
	VideoFlash Type = "flv"  // Flash Video
	VideoAVCHD Type = "mts"  // AVCHD (Advanced Video Coding High Definition)
	VideoBDAV  Type = "m2ts" // Blu-ray MPEG-2 Transport Stream
	VideoOGV   Type = "ogv"  // Ogg container format maintained by the Xiph.Org, free and open
	VideoASF   Type = "asf"  // Advanced Systems/Streaming Format (ASF)
	VideoWMV   Type = "wmv"  // Windows Media Video (based on ASF)
	VideoDV    Type = "dv"   // DV Video (https://en.wikipedia.org/wiki/DV)
)

Supported media.Video file types:

const (
	VectorSVG Type = "svg" // Scalable Vector Graphics
	VectorAI  Type = "ai"  // Adobe Illustrator
	VectorPS  Type = "ps"  // Adobe PostScript
	VectorEPS Type = "eps" // Encapsulated PostScript
)

Supported media.Vector file types:

const (
	SidecarXMP      Type = "xmp"  // Adobe XMP sidecar file (XML)
	SidecarXML      Type = "xml"  // XML metadata / config / sidecar file
	SidecarAAE      Type = "aae"  // Apple image edits sidecar file (based on XML)
	SidecarYAML     Type = "yml"  // YAML metadata / config / sidecar file
	SidecarJSON     Type = "json" // JSON metadata / config / sidecar file
	SidecarText     Type = "txt"  // Text config / sidecar file
	SidecarInfo     Type = "nfo"  // Info text file as used by e.g. Plex Media Server
	SidecarMarkdown Type = "md"   // Markdown text sidecar file
)

Supported media.Sidecar file types:

const TypeUnknown Type = ""

TypeUnknown is the default type used when a file cannot be classified.

func FileType

func FileType(fileName string) Type

FileType returns the type associated with the specified filename, and TypeUnknown if it could not be matched.

func NewType

func NewType(ext string) Type

NewType creates a new file type from a filename extension.

func (Type) DefaultExt

func (t Type) DefaultExt() string

DefaultExt returns the default file format extension with dot.

func (Type) Equal

func (t Type) Equal(s string) bool

Equal checks if the type matches.

func (Type) Find

func (t Type) Find(fileName string, stripSequence bool) string

Find returns the first filename with the same base name and a given type.

func (Type) FindAll

func (t Type) FindAll(fileName string, dirs []string, baseDir string, stripSequence bool) (results []string)

FindAll searches a list of directories for files with the same base name and a given type.

func (Type) FindFirst

func (t Type) FindFirst(fileName string, dirs []string, baseDir string, stripSequence bool) string

FindFirst searches a list of directories for the first file with the same base name and a given type.

func (Type) NotEqual

func (t Type) NotEqual(s string) bool

NotEqual checks if the type is different.

func (Type) String

func (t Type) String() string

String returns the file format as string.

type TypeMap

type TypeMap map[Type]string

type TypesExt

type TypesExt map[Type][]string

TypesExt maps standard formats to file extensions.

Jump to

Keyboard shortcuts

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