1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/stdlib/strings/decode.go

30 lines
674 B
Go
Raw Normal View History

2018-10-14 17:45:06 +02:00
package strings
import (
"context"
"encoding/base64"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
2018-10-28 20:15:54 +02:00
// FromBase64 returns the value of a base64 representation.
// @param base64String (String) - The string to decode.
// @returns value (String) - The decoded string.
2018-10-14 17:45:06 +02:00
func FromBase64(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.EmptyString, err
}
value := args[0].String()
out, err := base64.StdEncoding.DecodeString(value)
if err != nil {
return values.EmptyString, err
}
return values.NewString(string(out)), nil
}