From 5fb19074b566f4de639fe70f227cc01b09ceaf34 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Tue, 9 Jul 2024 23:42:30 -0600 Subject: [PATCH] fixup! lottie: add convert function Signed-off-by: Sumner Evans --- lottie/convert.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/lottie/convert.go b/lottie/convert.go index 8300a55..192d96f 100644 --- a/lottie/convert.go +++ b/lottie/convert.go @@ -39,8 +39,7 @@ func SetPath(path string) { // Convert converts lottie data an image or image(s) using lottieconverter. // // Args: -// - inputFilename: the filename the lottie file to convert. -// - inputReader: an io.Reader containing the lottie data to convert. +// - input: an io.Reader containing the lottie data to convert. // - outputFilename: the filename to write the output to. // - outputWriter: an io.Writer to write the output to. // - format: the output format. Can be one of: png, gif, or pngs. @@ -48,25 +47,16 @@ func SetPath(path string) { // - height: the height of the output image(s). // - extraArgs: additional arguments to pass to lottieconverter. // -// The inputFilename and inputReader parameters are mutually exclusive. // The outputFilename and outputWriter parameters are mutually exclusive. -func Convert(ctx context.Context, inputFilename string, inputReader io.Reader, outputFilename string, outputWriter io.Writer, format string, width, height int, extraArgs ...string) error { +func Convert(ctx context.Context, input io.Reader, outputFilename string, outputWriter io.Writer, format string, width, height int, extraArgs ...string) error { // Verify the input parameters and calculate the actual filenames that will // be used when shelling out to lottieconverter. // // We are panicking here because it's a programming error to call this // function with invalid parameters. - in := inputFilename out := outputFilename - if inputFilename == "" && inputReader == nil { - panic("lottie.Convert: either inputFile or inputReader must be provided") - } else if outputFilename == "" && outputWriter == nil { + if outputFilename == "" && outputWriter == nil { panic("lottie.Convert: either outputFile or outputWriter must be provided") - } else if inputReader != nil { - if inputFilename != "" { - panic("lottie.Convert: only one of inputFile or inputReader can be provided") - } - in = "-" } else if outputWriter != nil { if outputFilename != "" { panic("lottie.Convert: only one of outputFile or outputWriter can be provided") @@ -74,11 +64,11 @@ func Convert(ctx context.Context, inputFilename string, inputReader io.Reader, o out = "-" } - args := []string{in, out, format, fmt.Sprintf("%dx%d", width, height)} + args := []string{"-", out, format, fmt.Sprintf("%dx%d", width, height)} args = append(args, extraArgs...) cmd := exec.CommandContext(ctx, lottieconverterPath, args...) - cmd.Stdin = inputReader + cmd.Stdin = input cmd.Stdout = outputWriter log := zerolog.Ctx(ctx).With().Str("command", "lottieconverter").Logger() cmd.Stderr = exzerolog.NewLogWriter(log).WithLevel(zerolog.WarnLevel)