1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-10-30 23:37:40 +02:00
Files
ferret/pkg/stdlib/io/fs/read.go
Gavin Inglis 0f3526c178 refactor: remove io/ioutil (#792)
io/ioutil has been deprecated since Go 1.16
https://pkg.go.dev/io/ioutil

Signed-off-by: ginglis13 <ginglis05@gmail.com>
2025-05-07 10:51:10 -04:00

38 lines
839 B
Go

package fs
import (
"context"
"os"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// READ reads from a given file.
// @param {String} path - Path to file to read from.
// @return {Binary} - File content in binary format.
func Read(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.None, core.Error(err, "validate arguments number")
}
err = core.ValidateType(args[0], types.String)
if err != nil {
return values.None, core.Error(err, "validate [0] argument")
}
path := args[0].String()
data, err := os.ReadFile(path)
if err != nil {
return values.None, core.Error(err, "read file")
}
return values.NewBinary(data), nil
}