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
- Variables
- func ExportCSV(dir, prefix string, headers []string, rows [][]string) (string, error)
- func ExportEventsICS(dir string, events []iserv.CalendarEvent) (string, error)
- func ExportJSON(dir, prefix string, data any) (string, error)
- func SanitizeFileName(raw string) (string, error)
- func WriteBytes(baseDir, rawFileName string, data []byte) (string, error)
- func WriteStream(baseDir, rawFileName string, r io.Reader) (string, int64, error)
Constants ¶
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 ¶
var ErrInvalidFileName = errors.New("invalid or unsafe file name")
ErrInvalidFileName indicates a file name that is empty or attempts directory traversal.
Functions ¶
func ExportCSV ¶
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 ¶
ExportJSON writes indented JSON data inside dir using os.OpenRoot confinement.
func SanitizeFileName ¶
SanitizeFileName extracts a safe base file name stripped of path separators and control characters. Returns ErrInvalidFileName if no safe base name exists.
func WriteBytes ¶
WriteBytes writes data to baseDir/fileName inside an os.Root with 0600 permissions.
func WriteStream ¶
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.