Debian Codegraph @

execution/func_base64.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "encoding/base64"
6
7 "github.com/tomwright/dasel/v3/model"
8 )
9
10 // FuncBase64Encode base64 encodes the given value.
11 var FuncBase64Encode = NewFunc(
12 "base64e",
13 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
14 arg := args[0]
15 strVal, err := arg.StringValue()
16 if err != nil {
17 return nil, err
18 }
19 out := base64.StdEncoding.EncodeToString([]byte(strVal))
20 return model.NewStringValue(out), nil
21 },
22 ValidateArgsExactly(1),
23 )
24
25 // FuncBase64Decode base64 decodes the given value.
26 var FuncBase64Decode = NewFunc(
27 "base64d",
28 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
29 arg := args[0]
30 strVal, err := arg.StringValue()
31 if err != nil {
32 return nil, err
33 }
34 out, err := base64.StdEncoding.DecodeString(strVal)
35 if err != nil {
36 return nil, err
37 }
38 return model.NewStringValue(string(out)), nil
39 },
40 ValidateArgsExactly(1),
41 )