mirror of
https://git.unlock-music.dev/um/cli.git
synced 2025-07-07 06:52:10 +08:00
fix #18: skip noop decoder
This commit is contained in:
@ -7,12 +7,24 @@ import (
|
||||
|
||||
type NewDecoderFunc func([]byte) Decoder
|
||||
|
||||
var decoderRegistry = make(map[string][]NewDecoderFunc)
|
||||
type decoderItem struct {
|
||||
noop bool
|
||||
decoder NewDecoderFunc
|
||||
}
|
||||
|
||||
func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) {
|
||||
decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc)
|
||||
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) []NewDecoderFunc {
|
||||
func GetDecoder(filename string, skipNoop bool) (rs []NewDecoderFunc) {
|
||||
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
|
||||
return decoderRegistry[ext]
|
||||
for _, dec := range decoderRegistry[ext] {
|
||||
if skipNoop && dec.noop {
|
||||
continue
|
||||
}
|
||||
rs = append(rs, dec.decoder)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user