33 lines
889 B
Go
33 lines
889 B
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// builtin-os-file.go
|
|
package expr
|
|
|
|
import (
|
|
"git.portale-stac.it/go-pkg/expr/file"
|
|
"git.portale-stac.it/go-pkg/expr/kern"
|
|
)
|
|
|
|
const paramHandleOrPath = "handle-or-path"
|
|
|
|
func initFileHandle(ctx kern.ExprContext, name string, args map[string]any) (handle *file.Reader, invalidFileHandle any, autoClose bool, err error) {
|
|
var ok bool
|
|
|
|
if handle, ok = args[paramHandleOrPath].(*file.Reader); !ok {
|
|
if fileName, ok := args[paramHandleOrPath].(string); ok && len(fileName) > 0 {
|
|
var handleAny any
|
|
if handleAny, err = openFileFunc(ctx, name, map[string]any{kern.ParamFilepath: fileName}); err != nil {
|
|
return
|
|
}
|
|
if handleAny != nil {
|
|
handle = handleAny.(*file.Reader)
|
|
autoClose = true
|
|
}
|
|
} else {
|
|
invalidFileHandle = args[paramHandleOrPath]
|
|
}
|
|
}
|
|
return
|
|
}
|