fileutil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseFile

func CloseFile(file io.Closer) error

func CopyFile

func CopyFile(ctx context.Context, from string, to string) error

func DeleteFile

func DeleteFile(ctx context.Context, filename string) error

func FileExists

func FileExists(ctx context.Context, filename string) (bool, error)

func FileStats added in v0.6.0

func FileStats(ctx context.Context, filename string) (os.FileInfo, error)

func IsDefaultOSFileSystem added in v0.8.6

func IsDefaultOSFileSystem(ctx context.Context) bool

IsDefaultOSFileSystem reports whether ctx uses HuGo's native OS filesystem. Callers can use this to select APIs that require real local paths without probing the path itself (which could also exist locally for a custom adapter).

func IsLocalPath added in v0.9.0

func IsLocalPath(ctx context.Context, filename string) (bool, error)

IsLocalPath reports whether filename can be passed directly to native APIs that require a local operating system path. Custom filesystems must opt in by implementing LocalPathFileSystem; other adapters are treated as non-local.

func NewFileWriter

func NewFileWriter(ctx context.Context, filename string, contentType string) (io.WriteCloser, error)

func OpenFile

func OpenFile(ctx context.Context, filename string) (io.ReadCloser, error)

func PathJoinSafe

func PathJoinSafe(elem ...string) string

PathJoinSafe wrapper around filepath.Join to ensure that paths are correctly constructed if the path is a normal OS path, just use filepath.Join if the path is an object storage URI, trim any trailing slashes and construct it manually from the components so that double slashes (e.g. s3://) are preserved.

func ReadFileBytes

func ReadFileBytes(ctx context.Context, filename string) ([]byte, error)

func ReadLine

func ReadLine(r *bufio.Reader) ([]byte, error)

ReadLine returns a single line (without the ending \n) from the input buffered reader. An error is returned if there is an error with the buffered reader. This function is needed to avoid the 65K char line limit.

func WalkDir

func WalkDir(ctx context.Context, URL string, handler OnVisit) error

func WithFileSystem added in v0.7.8

func WithFileSystem(ctx context.Context, system FileSystem) context.Context

WithFileSystem binds a filesystem to a context. This is the preferred session-scoped injection mechanism.

Types

type FileSystem added in v0.7.8

type FileSystem interface {
	OpenFile(ctx context.Context, filename string) (io.ReadCloser, error)
	CopyFile(ctx context.Context, from string, to string) error
	Walk(ctx context.Context, URL string, handler OnVisit) error
	DeleteFile(ctx context.Context, filename string) error
	FileExists(ctx context.Context, filename string) (bool, error)
	FileStats(ctx context.Context, filename string) (os.FileInfo, error)
	NewFileWriter(ctx context.Context, filename string, contentType string) (io.WriteCloser, error)
}

FileSystem is the storage contract used by Hugot. The default implementation uses the local operating system, while applications can provide an adapter for object storage or another filesystem.

type LocalPathFileSystem added in v0.9.0

type LocalPathFileSystem interface {
	IsLocalPath(ctx context.Context, filename string) (bool, error)
}

LocalPathFileSystem is an optional capability for adapters whose paths may also be directly accessed by native APIs that require an operating system path. Returning true promises that filename refers to the same local files the adapter exposes through its other methods.

type OnVisit added in v0.7.8

type OnVisit func(ctx context.Context, URL string, parent string, info os.FileInfo, reader io.Reader) (toContinue bool, err error)

OnVisit is called for each file or directory encountered by WalkDir. parent is relative to the URL passed to WalkDir and reader is provided for files.

type PathType added in v0.7.8

type PathType uint8
const (
	PathTypeLocal PathType = iota
	PathTypeS3
	PathTypeGCP
	PathTypeAzureBlob
)

Jump to

Keyboard shortcuts

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