not tracked not covered covered

    // Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
    // All rights reserved.

    // file.go
    package file

    import (
            "os"

            "git.portale-stac.it/go-pkg/expr/kern"
    )

    type Handle interface {
            kern.Typer
            GetFile() *os.File
            GetName() string
            Valid() bool
            Close() error
    }

    type handleBase struct {
            fh *os.File
    }

    func (h *handleBase) GetFile() *os.File {
            return h.fh
    }

    func (h *handleBase) GetName() (name string) {
            if h.fh != nil {
                    name = h.fh.Name()
            }
            return
    }

    func (h *handleBase) Valid() bool {
            return h.fh != nil
    }

    func (h *handleBase) Close() (err error) {
            if h.fh != nil {
                    err = h.fh.Close()
                    h.fh = nil
            }
            return
    }

    // Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
    // All rights reserved.

    // reader.go
    package file

    import (
            "bufio"
            "io"
            "os"
    )

    type Reader struct {
            // fh     *os.File
            handleBase
            reader *bufio.Reader
    }

    func NewReader(fh *os.File) *Reader {
            return &Reader{handleBase: handleBase{fh: fh}, reader: bufio.NewReader(fh)}
    }

    func OpenReader(filePath string) (r *Reader, err error) {
            var fh *os.File
            if fh, err = os.Open(filePath); err == nil {
                    r = NewReader(fh)
            }
            return
    }

    func (h *Reader) TypeName() string {
            return "fileReader"
    }

    func (h *Reader) String() string {
            return "reader"
    }

    func (h *Reader) Valid() bool {
            return h.handleBase.Valid() && h.reader != nil
    }

    func (w *Reader) Close() (err error) {
            w.reader = nil
            err = w.handleBase.Close()
            return
    }

    func (h *Reader) ReadByte() (b byte, err error) {
            if h.reader != nil {
                    b, err = h.reader.ReadByte()
            } else {
                    err = io.ErrClosedPipe
            }
            return
    }

    func (h *Reader) ReadAll() (p []byte, err error) {
            if h.reader != nil {
                    p, err = io.ReadAll(h.reader)
            } else {
                    err = io.ErrClosedPipe
            }
            return
    }

    func (h *Reader) ReadString(delim byte) (s string, err error) {
            if h.reader != nil {
                    s, err = h.reader.ReadString(delim)
            } else {
                    err = io.ErrClosedPipe
            }
            return
    }

    func (h *Reader) Reset() (err error) {
            if h.fh != nil {
                    if _, err = h.fh.Seek(0, 0); err == nil {
                            h.reader.Reset(h.fh)
                    }
            }
            return
    }

    // Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
    // All rights reserved.

    // writer.go
    package file

    import (
            "bufio"
            "fmt"
            "os"
    )

    type Writer struct {
            // fh     *os.File
            handleBase
            writer *bufio.Writer
    }

    func NewWriter(fh *os.File) *Writer {
            return &Writer{handleBase: handleBase{fh: fh}, writer: bufio.NewWriter(fh)}
    }

    func CreateWriter(filePath string) (w *Writer, err error) {
            var fh *os.File
            if fh, err = os.Create(filePath); err == nil {
                    w = NewWriter(fh)
            }
            return
    }

    func AppendWriter(filePath string) (w *Writer, err error) {
            var fh *os.File
            if fh, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644); err == nil {
                    w = NewWriter(fh)
            }
            return
    }

    func (w *Writer) TypeName() string {
            return "fileWriter"
    }

    func (w *Writer) String() string {
            return "writer"
    }

    func (w *Writer) Valid() bool {
            return w.handleBase.Valid() && w.writer != nil
    }

    func (w *Writer) Close() (err error) {
            var err1 error
            if w.writer != nil {
                    err1 = w.Flush()
                    w.writer = nil
            }
            if err = w.handleBase.Close(); err == nil {
                    err = err1
            }
            return
    }

    func (w *Writer) Flush() (err error) {
            if w.writer != nil {
                    err = w.writer.Flush()
            }
            return
    }

    func (w *Writer) Write(args ...any) (n int, err error) {
            if w.writer != nil {
                    n, err = fmt.Fprint(w.writer, args...)
            }
            return
    }

    func (w *Writer) Writef(format string, args ...any) (n int, err error) {
            if w.writer != nil {
                    n, err = fmt.Fprintf(w.writer, format, args...)
            }
            return
    }