icns

Easily create .icns files (Mac Icons) with this Go library or the included CLI.
Log | Files | Refs | LICENSE

commit 4f1b88a2242dc18db2c34a5332bfd9f6d12df0ad
parent 4dc1c00d2b63e8fccaa4248b9706d0b79aae0b06
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Sun, 18 Feb 2018 00:19:50 +0100

[+] Added errors as sanity checks.

Diffstat:
Mreader.go | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/reader.go b/reader.go @@ -3,10 +3,12 @@ package icns import ( "bytes" "encoding/binary" - "errors" + "fmt" "image" "io" "io/ioutil" + + "github.com/pkg/errors" ) // Decode finds the largest icon listed in the icns file and returns it, @@ -19,7 +21,7 @@ func Decode(r io.Reader) (image.Image, error) { } icnsHeader := data[0:4] if string(icnsHeader) != "icns" { - return nil, errors.New("invalid header for icns file") + return nil, fmt.Errorf("invalid header for icns file") } fileSize := binary.BigEndian.Uint32(data[4:8]) icons := []iconReader{} @@ -46,6 +48,9 @@ func Decode(r io.Reader) (image.Image, error) { }) } } + if len(icons) == 0 { + return nil, fmt.Errorf("no icons found") + } var biggest iconReader for _, icon := range icons { if icon.Size > biggest.Size { @@ -54,7 +59,7 @@ func Decode(r io.Reader) (image.Image, error) { } img, _, err := image.Decode(biggest.r) if err != nil { - return nil, err + return nil, errors.Wrap(err, "decoding largest image") } return img, nil }