Documentation
¶
Index ¶
- func CloseFile(file io.Closer) error
- func CopyFile(ctx context.Context, from string, to string) error
- func DeleteFile(ctx context.Context, filename string) error
- func FileExists(ctx context.Context, filename string) (bool, error)
- func FileStats(ctx context.Context, filename string) (os.FileInfo, error)
- func IsDefaultOSFileSystem(ctx context.Context) bool
- func IsLocalPath(ctx context.Context, filename string) (bool, error)
- func NewFileWriter(ctx context.Context, filename string, contentType string) (io.WriteCloser, error)
- func OpenFile(ctx context.Context, filename string) (io.ReadCloser, error)
- func PathJoinSafe(elem ...string) string
- func ReadFileBytes(ctx context.Context, filename string) ([]byte, error)
- func ReadLine(r *bufio.Reader) ([]byte, error)
- func WalkDir(ctx context.Context, URL string, handler OnVisit) error
- func WithFileSystem(ctx context.Context, system FileSystem) context.Context
- type FileSystem
- type LocalPathFileSystem
- type OnVisit
- type PathType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDefaultOSFileSystem ¶ added in v0.8.6
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
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 PathJoinSafe ¶
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 ReadLine ¶
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 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.