⬥ ID3 encoding/decoding library in Go ⬥
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
846 B

package v2
import (
"fmt"
"io"
)
// Reads the whole ID3v2 tag from rs
func ReadV2Tag(rs io.ReadSeeker) (*ID3v2Tag, error) {
header, err := ReadHeader(rs)
if err != nil {
return nil, fmt.Errorf("could not get header: %s", err)
}
// collect frames
var read uint64 = 10 // because already read header
var frames []Frame
for {
if read > uint64(header.Size) {
break
}
frame, r, err := ReadNextFrame(rs, header)
if err == ErrGotPadding || err == ErrBiggerThanSize {
break
}
if err != nil {
return nil, fmt.Errorf("could not read frame: %s", err)
}
read += r
frames = append(frames, frame)
}
// create a map from collected frames
framesMp := make(map[string]Frame)
for _, frame := range frames {
framesMp[frame.Header.ID] = frame
}
return &ID3v2Tag{
Header: header,
Frames: framesMp,
}, nil
}