Add image frame

develop
Michael Yang 2013-12-19 23:31:47 -05:00
rodzic 1c1bfc4ff8
commit d563924708
1 zmienionych plików z 47 dodań i 0 usunięć

Wyświetl plik

@ -3,6 +3,10 @@
// license that can be found in the LICENSE file.
package id3
import (
"bytes"
)
const (
FrameHeaderSize = 10
)
@ -105,3 +109,46 @@ func NewUnsynchTextFrame(head FrameHead, data []byte) Framer {
return f
}
type ImageFrame struct {
FrameHead
DataFrame
Encoding string
MIMEType string
PictureType byte
Description string
}
func NewImageFrame(head FrameHead, data []byte) Framer {
f := &ImageFrame{FrameHead: head}
var err error
encodingIndex := data[0]
f.Encoding = encodingForIndex(encodingIndex)
buffer := bytes.NewBuffer(data[1:])
if f.MIMEType, err = buffer.ReadString(0); err != nil {
return nil
}
if f.PictureType, err = buffer.ReadByte(); err != nil {
return nil
}
beginIndex := 1 + len(f.MIMEType) + 1
var cutoff int
if i := afterNullIndex(data[beginIndex:], f.Encoding); i < 0 {
return nil
} else {
cutoff = beginIndex + i
}
if f.Description, err = Decoders[encodingIndex].ConvertString(string(data[beginIndex:cutoff])); err != nil {
return nil
}
f.Data = data[cutoff:]
return f
}