You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
872 B
Go
38 lines
872 B
Go
package common
|
|
|
|
import (
|
|
"io"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type DecoderParams struct {
|
|
Reader io.ReadSeeker // required
|
|
Extension string // required, source extension, eg. ".mp3"
|
|
|
|
FilePath string // optional, source file path
|
|
}
|
|
type NewDecoderFunc func(p *DecoderParams) Decoder
|
|
|
|
type decoderItem struct {
|
|
noop bool
|
|
decoder NewDecoderFunc
|
|
}
|
|
|
|
var DecoderRegistry = make(map[string][]decoderItem)
|
|
|
|
func RegisterDecoder(ext string, noop bool, dispatchFunc NewDecoderFunc) {
|
|
DecoderRegistry[ext] = append(DecoderRegistry[ext],
|
|
decoderItem{noop: noop, decoder: dispatchFunc})
|
|
}
|
|
func GetDecoder(filename string, skipNoop bool) (rs []NewDecoderFunc) {
|
|
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
|
|
for _, dec := range DecoderRegistry[ext] {
|
|
if skipNoop && dec.noop {
|
|
continue
|
|
}
|
|
rs = append(rs, dec.decoder)
|
|
}
|
|
return
|
|
}
|