kopia lustrzana https://github.com/jcs/id3-go
Merge pull request #13 from gerow/utf16_comm_write_fix
Fixed the way id3-go writes back comm tags when using utf16develop
commit
bcd5d72721
|
@ -51,7 +51,14 @@ func (w *Writer) WriteString(s string, encoding byte) (err error) {
|
|||
func (w *Writer) WriteNullTermString(s string, encoding byte) (err error) {
|
||||
err = w.WriteString(s, encoding)
|
||||
if err == nil {
|
||||
err = w.WriteByte(0)
|
||||
nullLength := EncodingMap[encoding].NullLength
|
||||
|
||||
for i := 0; i < nullLength; i++ {
|
||||
err = w.WriteByte(0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
40
id3_test.go
40
id3_test.go
|
@ -6,6 +6,7 @@ package id3
|
|||
import (
|
||||
"bytes"
|
||||
v2 "github.com/mikkyang/id3-go/v2"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
@ -37,6 +38,24 @@ func TestOpen(t *testing.T) {
|
|||
if s := tag.Album(); s != "Chief Life" {
|
||||
t.Errorf("Open: incorrect album, %v", s)
|
||||
}
|
||||
|
||||
parsedFrame := file.Frame("COMM")
|
||||
resultFrame, ok := parsedFrame.(*v2.UnsynchTextFrame)
|
||||
if !ok {
|
||||
t.Error("Couldn't cast frame")
|
||||
}
|
||||
|
||||
expected := "✓"
|
||||
actual := resultFrame.Description()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("Expected %q, got %q", expected, actual)
|
||||
}
|
||||
|
||||
actual = resultFrame.Text()
|
||||
if expected != actual {
|
||||
t.Errorf("Expected %q, got %q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClose(t *testing.T) {
|
||||
|
@ -152,3 +171,24 @@ func TestUnsynchTextFrame_RoundTrip(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUTF16CommPanic(t *testing.T) {
|
||||
osFile, err := os.Open(testFile)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tempfile, err := ioutil.TempFile("", "utf16_comm")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
io.Copy(tempfile, osFile)
|
||||
osFile.Close()
|
||||
tempfile.Close()
|
||||
for i := 0; i < 2; i++ {
|
||||
file, err := Open(tempfile.Name())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
}
|
||||
|
|
BIN
test.mp3
BIN
test.mp3
Plik binarny nie jest wyświetlany.
Ładowanie…
Reference in New Issue