safeio

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package safeio provides path-traversal-hardened file download and data export helpers confined to target directories using Go 1.24+ os.OpenRoot.

Index

Constants

View Source
const (
	// DefaultDownloadsDir is the default directory for downloaded WebDAV files.
	DefaultDownloadsDir = "downloads"
	// DefaultExportsDir is the default directory for exported ICS/JSON/CSV files.
	DefaultExportsDir = "exports"
)

Variables

View Source
var ErrInvalidFileName = errors.New("invalid or unsafe file name")

ErrInvalidFileName indicates a file name that is empty or attempts directory traversal.

Functions

func ExportCSV

func ExportCSV(dir, prefix string, headers []string, rows [][]string) (string, error)

ExportCSV writes UTF-8 CSV rows inside dir using os.OpenRoot confinement.

func ExportEventsICS

func ExportEventsICS(dir string, events []iserv.CalendarEvent) (string, error)

ExportEventsICS writes calendar events as an RFC 5545 .ics file inside dir.

func ExportJSON

func ExportJSON(dir, prefix string, data any) (string, error)

ExportJSON writes indented JSON data inside dir using os.OpenRoot confinement.

func SanitizeFileName

func SanitizeFileName(raw string) (string, error)

SanitizeFileName extracts a safe base file name stripped of path separators and control characters. Returns ErrInvalidFileName if no safe base name exists.

func WriteBytes

func WriteBytes(baseDir, rawFileName string, data []byte) (string, error)

WriteBytes writes data to baseDir/fileName inside an os.Root with 0600 permissions.

func WriteStream

func WriteStream(baseDir, rawFileName string, r io.Reader) (string, int64, error)

WriteStream writes r into baseDir/fileName using os.OpenRoot confinement and owner-only 0600 permissions, returning the resulting file path and byte count.

Types

This section is empty.

Jump to

Keyboard shortcuts

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