@@ -3,6 +3,7 @@ package export
33import (
44 "bytes"
55 "os"
6+ "path/filepath"
67
78 "github.com/mrmarble/termsvg/internal/svg"
89 "github.com/mrmarble/termsvg/pkg/asciicast"
@@ -37,7 +38,7 @@ func (cmd *Cmd) Run() error {
3738}
3839
3940func export (input , output string , mini bool , bgColor , textColor string , noWindow bool ) error {
40- inputFile , err := os .ReadFile (input )
41+ inputFile , err := os .ReadFile (filepath . Clean ( input ) )
4142 if err != nil {
4243 return err
4344 }
@@ -47,31 +48,31 @@ func export(input, output string, mini bool, bgColor, textColor string, noWindow
4748 return err
4849 }
4950
50- outputFile , err := os .Create (output )
51- if err != nil {
52- return err
53- }
54- defer outputFile .Close ()
51+ out := new (bytes.Buffer )
52+ var data []byte
5553
54+ svg .Export (* cast , out , bgColor , textColor , noWindow )
5655 if mini {
57- out := new (bytes.Buffer )
58- svg .Export (* cast , out , bgColor , textColor , noWindow )
59-
6056 m := minify .New ()
6157 m .AddFunc ("image/svg+xml" , msvg .Minify )
62-
6358 b , err := m .Bytes ("image/svg+xml" , out .Bytes ())
6459 if err != nil {
6560 return err
6661 }
67-
68- _ , err = outputFile .Write (b )
69- if err != nil {
70- return err
71- }
62+ data = b
7263 } else {
73- svg .Export (* cast , outputFile , bgColor , textColor , noWindow )
64+ data = out .Bytes ()
65+ }
66+ outputFile , err := os .Create (output )
67+ if err != nil {
68+ return err
69+ }
70+ _ , err = outputFile .Write (data )
71+ if err != nil {
72+ //nolint:gosec,errcheck
73+ outputFile .Close ()
74+ return err
7475 }
7576
76- return nil
77+ return outputFile . Close ()
7778}
0 commit comments