@@ -188,8 +188,8 @@ type ImageDesc struct {
188188 Type string
189189 // Description is a textual description of the image
190190 Description string
191- // MimeType is the MIME type of the image (e.g., "image/jpeg")
192- MimeType string
191+ // MIMEType is the MIME type of the image (e.g., "image/jpeg")
192+ MIMEType string
193193}
194194
195195// ReadProperties reads the audio properties from a file at the given path.
@@ -215,13 +215,14 @@ func ReadProperties(path string) (Properties, error) {
215215 var images []ImageDesc
216216 for _ , row := range raw .imageDescs {
217217 parts := strings .SplitN (row , "\t " , 3 )
218- if len (parts ) == 3 {
219- images = append (images , ImageDesc {
220- Type : parts [0 ],
221- Description : parts [1 ],
222- MimeType : parts [2 ],
223- })
218+ if len (parts ) != 3 {
219+ continue
224220 }
221+ images = append (images , ImageDesc {
222+ Type : parts [0 ],
223+ Description : parts [1 ],
224+ MIMEType : parts [2 ],
225+ })
225226 }
226227
227228 return Properties {
@@ -280,7 +281,7 @@ func ReadImage(path string) ([]byte, error) {
280281func WriteImage (path string , image []byte ) error {
281282 mimeType := ""
282283 if image != nil {
283- mimeType = detectImageMimeType (image )
284+ mimeType = detectImageMIME (image )
284285 }
285286 return WriteImageOptions (path , image , 0 , "Front Cover" , "Added by go-taglib" , mimeType )
286287}
@@ -430,82 +431,78 @@ func (m *module) malloc(size uint32) uint32 {
430431}
431432
432433type wasmArg interface {
433- toWasm (* module ) uint64
434+ encode (* module ) uint64
434435}
435436
436437type wasmResult interface {
437- fromWasm (* module , uint64 )
438+ decode (* module , uint64 )
438439}
439440
440441type wasmBool bool
441442
442- func (b wasmBool ) toWasm (* module ) uint64 {
443+ func (b wasmBool ) encode (* module ) uint64 {
443444 if b {
444445 return 1
445446 }
446447 return 0
447448}
448449
449- func (b * wasmBool ) fromWasm (_ * module , val uint64 ) {
450+ func (b * wasmBool ) decode (_ * module , val uint64 ) {
450451 * b = val == 1
451452}
452453
453454type wasmInt int
454455
455- func (i wasmInt ) toWasm (* module ) uint64 { return uint64 (i ) }
456-
457- func (i * wasmInt ) fromWasm (_ * module , val uint64 ) {
456+ func (i wasmInt ) encode (* module ) uint64 { return uint64 (i ) }
457+ func (i * wasmInt ) decode (_ * module , val uint64 ) {
458458 * i = wasmInt (val )
459459}
460460
461461type wasmUint8 uint8
462462
463- func (u wasmUint8 ) toWasm (* module ) uint64 { return uint64 (u ) }
463+ func (u wasmUint8 ) encode (* module ) uint64 { return uint64 (u ) }
464464
465465type wasmUint32 uint32
466466
467- func (u wasmUint32 ) toWasm (* module ) uint64 { return uint64 (u ) }
468-
469- func (u * wasmUint32 ) fromWasm (_ * module , val uint64 ) {
467+ func (u wasmUint32 ) encode (* module ) uint64 { return uint64 (u ) }
468+ func (u * wasmUint32 ) decode (_ * module , val uint64 ) {
470469 * u = wasmUint32 (val )
471470}
472471
473472type wasmString string
474473
475- func (s wasmString ) toWasm (m * module ) uint64 {
474+ func (s wasmString ) encode (m * module ) uint64 {
476475 b := append ([]byte (s ), 0 )
477476 ptr := m .malloc (uint32 (len (b )))
478477 if ! m .mod .Memory ().Write (ptr , b ) {
479478 panic ("failed to write to mod.module.Memory()" )
480479 }
481480 return uint64 (ptr )
482481}
483-
484- func (s * wasmString ) fromWasm (m * module , val uint64 ) {
482+ func (s * wasmString ) decode (m * module , val uint64 ) {
485483 if val != 0 {
486484 * s = wasmString (readString (m , uint32 (val )))
487485 }
488486}
489487
490488type wasmBytes []byte
491489
492- func (b wasmBytes ) toWasm (m * module ) uint64 {
490+ func (b wasmBytes ) encode (m * module ) uint64 {
493491 ptr := m .malloc (uint32 (len (b )))
494492 if ! m .mod .Memory ().Write (ptr , b ) {
495493 panic ("failed to write to mod.module.Memory()" )
496494 }
497495 return uint64 (ptr )
498496}
499-
500- func (b * wasmBytes ) fromWasm (m * module , val uint64 ) {
497+ func (b * wasmBytes ) decode (m * module , val uint64 ) {
501498 if val != 0 {
502499 * b = readBytes (m , uint32 (val ))
503500 }
504501}
505502
506503type wasmStrings []string
507504
508- func (s wasmStrings ) toWasm (m * module ) uint64 {
505+ func (s wasmStrings ) encode (m * module ) uint64 {
509506 arrayPtr := m .malloc (uint32 ((len (s ) + 1 ) * 4 ))
510507 for i , str := range s {
511508 b := append ([]byte (str ), 0 )
@@ -522,8 +519,7 @@ func (s wasmStrings) toWasm(m *module) uint64 {
522519 }
523520 return uint64 (arrayPtr )
524521}
525-
526- func (s * wasmStrings ) fromWasm (m * module , val uint64 ) {
522+ func (s * wasmStrings ) decode (m * module , val uint64 ) {
527523 if val != 0 {
528524 * s = readStrings (m , uint32 (val ))
529525 }
@@ -537,7 +533,7 @@ type wasmFileProperties struct {
537533 imageDescs []string
538534}
539535
540- func (f * wasmFileProperties ) fromWasm (m * module , val uint64 ) {
536+ func (f * wasmFileProperties ) decode (m * module , val uint64 ) {
541537 if val == 0 {
542538 return
543539 }
@@ -557,7 +553,7 @@ func (f *wasmFileProperties) fromWasm(m *module, val uint64) {
557553func (m * module ) call (name string , dest wasmResult , args ... wasmArg ) error {
558554 params := make ([]uint64 , 0 , len (args ))
559555 for _ , a := range args {
560- params = append (params , a .toWasm (m ))
556+ params = append (params , a .encode (m ))
561557 }
562558
563559 results , err := m .mod .ExportedFunction (name ).Call (context .Background (), params ... )
@@ -568,7 +564,7 @@ func (m *module) call(name string, dest wasmResult, args ...wasmArg) error {
568564 return nil
569565 }
570566
571- dest .fromWasm (m , results [0 ])
567+ dest .decode (m , results [0 ])
572568 return nil
573569}
574570
@@ -604,6 +600,7 @@ func readString(m *module, ptr uint32) string {
604600 if i := bytes .IndexByte (buf , 0 ); i >= 0 {
605601 return string (buf [:i ])
606602 }
603+
607604 for {
608605 next , ok := m .mod .Memory ().Read (ptr + size , size )
609606 if ! ok {
@@ -634,9 +631,10 @@ func readBytes(m *module, ptr uint32) []byte {
634631 panic ("memory error" )
635632 }
636633
637- // copy the data, "this returns a view of the underlying memory, not a copy. " per api.memory.read docs
634+ // copy the data, "this returns a view of the underlying memory, not a copy" per api.Memory.Read docs
638635 ret = make ([]byte , size )
639636 copy (ret , b )
637+
640638 return ret
641639}
642640
@@ -645,9 +643,9 @@ func wasmPath(p string) string {
645643 return filepath .ToSlash (p )
646644}
647645
648- // detectImageMimeType detects image MIME type from magic bytes.
646+ // detectImageMIME detects image MIME type from magic bytes.
649647// Adapted from Go's net/http package to avoid the dependency.
650- func detectImageMimeType (data []byte ) string {
648+ func detectImageMIME (data []byte ) string {
651649 if len (data ) < 2 {
652650 return ""
653651 }
0 commit comments