From 20172223621bdf519fa8db6fecb62accebe9b218 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Mon, 17 Jul 2017 22:30:27 +0200 Subject: [PATCH] Make id3Identifier a byte slice --- header.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/header.go b/header.go index 8e4a5ea..5ea28ca 100644 --- a/header.go +++ b/header.go @@ -6,19 +6,21 @@ package id3v2 import ( "bufio" + "bytes" "errors" "io" "github.com/bogem/id3v2/util" ) -const ( - id3Identifier = "ID3" - tagHeaderSize = 10 -) +const tagHeaderSize = 10 + +var ( + id3Identifier = []byte("ID3") + errNoTag = errors.New("there is no tag in file") -var errNoTag = errors.New("there is no tag in file") -var ErrSmallHeaderSize = errors.New("size of tag header is less than expected") + ErrSmallHeaderSize = errors.New("size of tag header is less than expected") +) type tagHeader struct { FramesSize int64 @@ -58,12 +60,12 @@ func isID3Tag(data []byte) bool { if len(data) != len(id3Identifier) { return false } - return string(data[0:3]) == id3Identifier + return bytes.Equal(data, id3Identifier) } func writeTagHeader(bw *bufio.Writer, framesSize int, version byte) error { // Identifier - if _, err := bw.WriteString(id3Identifier); err != nil { + if _, err := bw.Write(id3Identifier); err != nil { return err }