commit 439e61a508660c5e2b595d9458bfd9489faf06fb
parent 5519ecdd0cf713a5d9d8288ea5cea4e6d987a511
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Tue, 29 Oct 2024 12:10:22 +0800
cmd/icnsify: probe icns prior to decode
Output the content of the icns prior to decode. This will help explain
any issues to caller by revealing unsupported file types.
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/cmd/icnsify/main.go b/cmd/icnsify/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"image"
"image/jpeg"
"image/png"
@@ -70,6 +71,22 @@ func main() {
defer outputf.Close()
output = outputf
}
+ if filepath.Ext(*inputPath) == ".icns" {
+ by, err := io.ReadAll(input)
+ if err != nil {
+ slog.Error("probing file: reading file", "err", err)
+ return
+ }
+ icons, err := icns.Probe(bytes.NewReader(by))
+ if err != nil {
+ slog.Error("probing file", "err", err)
+ return
+ }
+ for _, icon := range icons {
+ slog.Info("found", "icon", icon)
+ }
+ input = bytes.NewReader(by)
+ }
img, format, err := image.Decode(input)
if err != nil {
slog.Error("decoding input", "err", err)