ioHelpers

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 9

README

ioHelpers

ioHelpers provides file I/O utilities — read, write, copy, backup, dump, and directory management.

Functions

File Operations
Function Description
Read(fileName, path string) (string, error) Reads file contents as a string
Write(fileName, path, content string) (bool, error) Writes content to a file
WriteData(fileName, path, content string) int Writes data to a file (returns 1 on success)
Copy(fileName, fromPath, toPath string) bool Copies a file between paths
CopyFile(src, dst string) error Copies a file preserving permissions
Touch(filename string) bool Returns true if the file exists
Directory Operations
Function Description
MkDir(path string) error Creates a single directory
MkdirAll(path string) error Recursively creates directories
Dir(path string) ([]string, error) Lists subdirectory names
GetFolders(path string) ([]string, error) Lists subdirectory names
Empty(dir string) error Deletes all files in a directory
DeleteFolder(path string) error Removes a directory tree
Database & Debugging
Function Description
GetDBFileName(name string) string Constructs a database file path
Dump(tableName, where, action, recordID string, data any) JSON-dumps a record to a timestamped file
Backup(table, location string) Copies a DB file to a backup location

Example

import "github.com/mt1976/frantic-core/ioHelpers"

func main() {
    content, err := ioHelpers.Read("config.json", "./data")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(content)

    _, err = ioHelpers.Write("output.txt", "./data", "hello world")
    if err != nil {
        log.Fatal(err)
    }
}

Documentation

Overview

Package ioHelpers provides simple I/O utilities for files and streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(table, location string)

func Copy

func Copy(fileName string, fromPath string, toPath string) bool

The Copy function copies a file from one path to another and returns true if the copy was successful.

func CopyFile

func CopyFile(src, dst string) error

File copies a single file from src to dst

func DeleteFolder

func DeleteFolder(path string) error

func Dir

func Dir(path string) ([]string, error)

func Dump

func Dump(tableName string, where paths.FileSystemPath, action string, recordID string, yy any)

func Empty

func Empty(dir string) error

Empty clears the contents of a specified directory The function "Empty" deletes all files in a given directory.

func GetDBFileName

func GetDBFileName(name string) string

func GetFolders

func GetFolders(path string) ([]string, error)

func MkDir

func MkDir(path string) error

func MkdirAll

func MkdirAll(path string) error

func Read

func Read(fileName string, path string) (string, error)

The Read function reads the content of a file given its name and path, and returns the content as a string.

func Touch

func Touch(filename string) bool

Touch returns true if the specified file existing on the filesystem The Touch function takes a filename as input and returns a boolean value indicating whether the file was successfully touched.

func Write

func Write(fileName string, path string, content string) (bool, error)

The Write function writes content to a file specified by fileName and path, and returns a boolean indicating success and an error if any.

func WriteData

func WriteData(fileName string, path string, content string) int

The function `WriteData` writes the given content to a file with the specified name and path.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL