fsutil

package
v0.85.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

README

kit/fsutil

github.com/vormadev/vorma/kit/fsutil

Small filesystem helpers for common app/tooling tasks:

  • ensure directories exist
  • copy files/directories
  • decode gob files
  • fail-fast helpers for embedded filesystem access

Import

import "github.com/vormadev/vorma/kit/fsutil"

Quick Start

Ensure required directories
if err := fsutil.EnsureDirs("var/cache", "var/log", "var/tmp"); err != nil {
	return err
}
Copy a tree
if err := fsutil.CopyDir("./templates", "./build/templates"); err != nil {
	return err
}
Decode a gob file into a struct
f, err := os.Open("state.gob")
if err != nil {
	return err
}
defer f.Close()

state, err := fsutil.FromGob[AppState](f)
if err != nil {
	return err
}
_ = state

Behavior Notes

  • CopyFile creates/overwrites destination content.
  • CopyFile creates missing destination parent directories with mode 0755.
  • CopyFile preserves source file permission bits on destination file creation.
  • CopyDir recursively copies directory entries and delegates file copies to CopyFile.
  • CopyDir/CopyFile copy file contents and basic mode bits, not extended metadata.
  • MustSub and MustReadFile panic on error; use them where failure is unrecoverable (for example required embedded assets).
  • CallerDir returns the directory of the direct caller frame.

API Coverage

Functions
  • func CopyDir(src, dst string) error
  • func CopyFile(src, dest string) error
  • func CopyFiles(srcDestTuples ...[2]string) error
  • func EnsureDir(path string) error
  • func EnsureDirs(paths ...string) error
  • func FromGob[T any](file fs.File) (T, error)
  • func FromGobInto(file fs.File, destPtr any) error
  • func CallerDir() string
  • func MustReadFile(f fs.FS, name string) []byte
  • func MustSub(f fs.FS, dirElems ...string) fs.FS

Documentation

Overview

Package fsutil provides utility functions for working with the filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies a directory from src to dst.

func CopyFile

func CopyFile(src, dest string) error

CopyFile copies a single file from src to dest

func CopyFiles

func CopyFiles(srcDestTuples ...[2]string) error

CopyFiles takes any number of src-dest tuples and copies each file from src to dest.

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates a directory if it does not exist.

func EnsureDirs

func EnsureDirs(paths ...string) error

func FromGob

func FromGob[T any](file fs.File) (T, error)

FromGob decodes a gob-encoded file into a value of type T.

func FromGobInto

func FromGobInto(file fs.File, destPtr any) error

FromGobInto decodes a gob-encoded file into a destination. The destination must be a pointer to the destination type.

func GetCallerDir

func GetCallerDir() string

CallerDir returns the directory of the calling function.

func MustReadFile

func MustReadFile(f fs.FS, name string) []byte

func MustSub

func MustSub(f fs.FS, dirElems ...string) fs.FS

Types

This section is empty.

Jump to

Keyboard shortcuts

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