iosafety

package
v0.0.0-...-ffc4fba Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package iosafety provides defensive file-reading and terminal-output utilities for user-supplied paths and strings.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDirectoryPath indicates a file operation was attempted on a directory.
	ErrDirectoryPath = errors.New("path points to a directory")
	// ErrEmptyPath indicates a path argument was empty.
	ErrEmptyPath = errors.New("path is empty")
	// ErrPathContainsNUL indicates the path contains a NUL byte.
	ErrPathContainsNUL = errors.New("path contains NUL byte")
)

Sentinel errors for path validation.

Functions

func ReadFile

func ReadFile(path string) (content []byte, resolvedPath string, err error)

ReadFile resolves, validates, and reads a user-supplied file path. Returns content, the resolved absolute path, and any error.

func ResolvePath

func ResolvePath(path string) (string, error)

ResolvePath normalises and validates a user-supplied file path. Returns the absolute path after cleaning, resolving, and stat-checking. Returns an error for empty paths, NUL bytes, directories, or stat failures.

func SanitizeForTerminal

func SanitizeForTerminal(input string) string

SanitizeForTerminal strips control characters and HTML-escapes the input. Newlines, carriage returns, and tabs are replaced with spaces.

Types

This section is empty.

Jump to

Keyboard shortcuts

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