const ( // MimetypeLeadBytesCount is the number of bytes to use for detection. MimetypeLeadBytesCount = 512 )
var ( // ErrLruEmpty indicates that the LRU is empty.. ErrLruEmpty = errors.New("lru is empty") )
func DetectMimetype(f *os.File) (mimetype string, err error)
DetectMimetype is a wrapper for GetMimetypeFromContent which returns the mime-type for the given `File`. An empty-string is returned if it is a zero- length file.
func GetMimetypeFromContent(r io.Reader, fileSize int64) (mimetype string, err error)
GetMimetypeFromContent uses net/http to map from magic-bytes to mime-type.
Lru establises an LRU of IDs of any type.
type Lru struct {
// contains filtered or unexported fields
}
func NewLru(maxSize int) *Lru
NewLru returns a new instance.
func (lru *Lru) All() []LruKey
All returns a list of all IDs.
func (lru *Lru) Count() int
Count returns the number of items in the LRU.
func (lru *Lru) Drop(id LruKey) (found bool, err error)
Drop discards the given item.
func (lru *Lru) Dump()
Dump returns a list of all IDs.
func (lru *Lru) Exists(id LruKey) bool
Exists will do a membership check for the given key.
func (lru *Lru) FindPosition(id LruKey) int
FindPosition will return the numerical position in the list. Since the LRU will never be very large, this call is not expensive, per se. But, it *is* O(n) and any call to us will compound with any loops you happen to wrap us into.
func (lru *Lru) Get(id LruKey) (found bool, item LruItem, err error)
Get touches the cache and returns the data.
func (lru *Lru) IsFull() bool
IsFull will return true if at capacity.
func (lru *Lru) MaxCount() int
MaxCount returns the maximum number of items the LRU can contain.
func (lru *Lru) Newest() LruKey
Newest returns the most recently used ID.
func (lru *Lru) Oldest() LruKey
Oldest returns the least recently used ID.
func (lru *Lru) PopOldest() (item LruItem, err error)
PopOldest will pop the oldest entry out of the LRU and return it. It will return ErrLruEmpty when empty.
func (lru *Lru) Set(item LruItem) (added bool, droppedItem LruItem, err error)
Set bumps an item to the front of the LRU. It will be added if it doesn't already exist. If as a result of adding an item the LRU exceeds the maximum size, the least recently used item will be discarded.
If it was not previously in the LRU, `added` will be `true`.
func (lru *Lru) SetDropCb(cb lruEventFunc)
SetDropCb sets a callback that will be triggered whenever an item ages out or is manually dropped.
LruItem is the interface that any item we add to the LRU must satisfy.
type LruItem interface { Id() LruKey }
LruKey is the type of an LRU key.
type LruKey interface{}