fix #18: support upper case extension

This commit is contained in:
Emmm Monster
2021-11-11 23:27:07 +08:00
parent 0a13671df2
commit 6fd5bd5863
3 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,10 @@
package common
import (
"path/filepath"
"strings"
)
type NewDecoderFunc func([]byte) Decoder
var decoderRegistry = make(map[string][]NewDecoderFunc)
@ -7,6 +12,7 @@ var decoderRegistry = make(map[string][]NewDecoderFunc)
func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) {
decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc)
}
func GetDecoder(ext string) []NewDecoderFunc {
func GetDecoder(filename string) []NewDecoderFunc {
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
return decoderRegistry[ext]
}

View File

@ -1,6 +1,9 @@
package common
import "errors"
import (
"errors"
"strings"
)
type RawDecoder struct {
file []byte
@ -14,7 +17,7 @@ func NewRawDecoder(file []byte) Decoder {
func (d *RawDecoder) Validate() error {
for ext, sniffer := range snifferRegistry {
if sniffer(d.file) {
d.audioExt = ext
d.audioExt = strings.ToLower(ext)
return nil
}
}