Skip to content

Commit

Permalink
chore: fix wrong mp3 content-type (#802)
Browse files Browse the repository at this point in the history
Because

 - The mp3 content-type was incorrect in the comment.

This commit

 - Fixes the incorrect mp3 content-type
 - Uses the built-in Equal function to compare byte arrays
  • Loading branch information
donch1989 authored Nov 3, 2024
1 parent a405bf7 commit f207d40
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/data/bytearray.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"bytes"
"encoding/base64"
"fmt"

Expand Down Expand Up @@ -45,7 +46,7 @@ func (b byteArrayData) ToStructValue() (v *structpb.Value, err error) {

func (b *byteArrayData) Equal(other format.Value) bool {
if other, ok := other.(format.ByteArray); ok {
return fmt.Sprintf("%x", b.Raw) == fmt.Sprintf("%x", other.ByteArray())
return bytes.Equal(b.Raw, other.ByteArray())
}
return false
}
3 changes: 2 additions & 1 deletion pkg/data/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"bytes"
"fmt"
"mime"
"strings"
Expand Down Expand Up @@ -202,7 +203,7 @@ func (f *fileData) Equal(other format.Value) bool {
if err != nil {
return false
}
return fmt.Sprintf("%x", f.raw) == fmt.Sprintf("%x", ba.ByteArray()) &&
return bytes.Equal(f.raw, ba.ByteArray()) &&
f.contentType == other.ContentType().String() &&
f.fileName == other.FileName().String() &&
f.sourceURL == other.SourceURL().String()
Expand Down
2 changes: 1 addition & 1 deletion pkg/data/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// The format portion of the tag supports:
// - For Image: "image/png", "image/jpeg", etc
// - For Video: "video/mp4", "video/webm", etc
// - For Audio: "audio/mp3", "audio/wav", etc
// - For Audio: "audio/mpeg", "audio/wav", etc
// - For Document: "application/pdf", "text/plain", etc

// Unmarshal converts a Map value into the provided struct s using `instill` tags.
Expand Down

0 comments on commit f207d40

Please sign in to comment.