Browse Source

Less verbose and more understandable function names

main
Unbewohnte 3 years ago
parent
commit
8b837a4539
  1. 10
      id3v10.go
  2. 4
      id3v10_test.go
  3. 8
      id3v11.go
  4. 4
      id3v11_test.go
  5. 15
      metadata.go

10
id3v10.go

@ -92,8 +92,8 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) {
}, nil
}
// Writes given ID3v1.0 tags to given io.ReadWriteSeeker.
func WriteID3v1Tags(dst io.WriteSeeker, tags *ID3v1Tags) error {
// Writes given ID3v1.0 tags to given io.WriteSeeker.
func (tags *ID3v1Tags) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd)
// TAG
@ -150,7 +150,7 @@ func WriteID3v1Tags(dst io.WriteSeeker, tags *ID3v1Tags) error {
}
// Checks for existing ID3v1 tag in file, if present - removes it and replaces with provided tags
func WriteID3v1ToFile(f *os.File, tags *ID3v1Tags) error {
func (tags *ID3v1Tags) WriteToFile(f *os.File) error {
defer f.Close()
// check for existing ID3v1 tag
@ -163,7 +163,7 @@ func WriteID3v1ToFile(f *os.File, tags *ID3v1Tags) error {
if !bytes.Equal(tag, []byte("TAG")) {
// no existing tag, just write given tags
err = WriteID3v1Tags(f, tags)
err = tags.Write(f)
if err != nil {
return err
}
@ -182,7 +182,7 @@ func WriteID3v1ToFile(f *os.File, tags *ID3v1Tags) error {
}
// writing new tags
err = WriteID3v1Tags(f, tags)
err = tags.Write(f)
if err != nil {
return err
}

4
id3v10_test.go

@ -40,7 +40,7 @@ func TestWriteID3v1Tags(t *testing.T) {
tags := TESTv1TAGS
err = WriteID3v1Tags(f, tags)
err = tags.Write(f)
if err != nil {
t.Errorf("WriteID3v1Tags failed: %s", err)
}
@ -67,7 +67,7 @@ func TestWriteID3v1ToFile(t *testing.T) {
tags := TESTv1TAGS
err = WriteID3v1ToFile(f, tags)
err = tags.WriteToFile(f)
if err != nil {
t.Errorf("WriteID3v1ToFile failed: %s", err)
}

8
id3v11.go

@ -107,7 +107,7 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) {
}
// Writes given ID3v1.1 tags to dst
func WriteID3v11Tags(dst io.WriteSeeker, tags *ID3v11Tags) error {
func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd)
// TAG
@ -178,7 +178,7 @@ func WriteID3v11Tags(dst io.WriteSeeker, tags *ID3v11Tags) error {
}
// Checks for existing ID3v1.1 tag in file, if present - removes it and replaces with provided tags
func WriteID3v11ToFile(f *os.File, tags *ID3v11Tags) error {
func (tags *ID3v11Tags) WriteToFile(f *os.File) error {
defer f.Close()
// check for existing ID3v1.1 tag
@ -191,7 +191,7 @@ func WriteID3v11ToFile(f *os.File, tags *ID3v11Tags) error {
if !bytes.Equal(tag, []byte("TAG")) {
// no existing tag, just write given tags
err = WriteID3v11Tags(f, tags)
err = tags.Write(f)
if err != nil {
return err
}
@ -210,7 +210,7 @@ func WriteID3v11ToFile(f *os.File, tags *ID3v11Tags) error {
}
// writing new tags
err = WriteID3v11Tags(f, tags)
err = tags.Write(f)
if err != nil {
return err
}

4
id3v11_test.go

@ -47,7 +47,7 @@ func TestWriteID3v11Tags(t *testing.T) {
tags := TESTV11TAGS
err = WriteID3v11Tags(f, tags)
err = tags.Write(f)
if err != nil {
t.Errorf("WriteID3v1Tags failed: %s", err)
}
@ -78,7 +78,7 @@ func TestWriteID3v11ToFile(t *testing.T) {
tags := TESTV11TAGS
err = WriteID3v11ToFile(f, tags)
err = tags.WriteToFile(f)
if err != nil {
t.Errorf("WriteID3v1ToFile failed: %s", err)
}

15
metadata.go

@ -0,0 +1,15 @@
package id3ed
import (
"io"
"os"
)
// I`m still a bit confused about interfaces,
// I`ll look into them and try to figure out
// how to use them properly
type Metadata interface {
Read(io.ReadSeeker) error
Write(io.WriteSeeker) error
WriteToFile(*os.File) error
}
Loading…
Cancel
Save