fs

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(filePath string, substring string) (bool, error)

Contains checks if the file at the specified file path contains the given substring. It opens the file, scans it line by line, and checks if any line contains the substring.

Parameters: - filePath: string The path of the file to check. - substring: string The substring to search for in the file.

Returns: - bool: true if the file contains the substring, false otherwise. - error: An error if any occurred during the process.

func CreateDirectory

func CreateDirectory(dirPath string, options ...*Options) error

CreateDirectory creates a directory at the specified path. If the directory already exists, it does nothing. This function allows specifying additional options for creating the directory. It also adds execute permissions to allow directory traversal.

Parameters: - dirPath: string The path where the directory will be created. - options: []*Options Optional parameters to specify directory options.

Returns: - error: An error if the directory creation fails.

func CreateFile

func CreateFile(filePath string, options ...*Options) (*os.File, error)

CreateFile creates a file at the specified file path with the given options. It wraps the createOrOpenFile function with specific flags for file creation.

Parameters: - filePath: string The path of the file to create. - options: []*Options Optional parameters to specify file options.

Returns: - *os.File: The created file. - error: An error if any occurred during the process.

func DeleteDirectory

func DeleteDirectory(dirPath string) error

DeleteDirectory deletes a directory at the specified path. It uses os.RemoveAll to delete the directory and all its contents.

Parameters: - dirPath: string The path of the directory to delete.

Returns: - error: An error if the directory deletion fails.

func DeleteFile

func DeleteFile(filePath string) error

DeleteFile deletes the file at the specified file path. It simply calls os.Remove to delete the file.

Parameters: - filePath: string The path of the file to delete.

Returns: - error: An error if any occurred during the process.

func ExistsDirectory

func ExistsDirectory(dirPath string) bool

ExistsDirectory checks if a directory exists at the specified path. It uses os.Stat to get file information and determines if the path is a directory.

Parameters: - dirPath: string The path of the directory to check.

Returns: - bool: true if the directory exists, false otherwise.

func ExistsFile

func ExistsFile(filePath string) (bool, error)

ExistsFile checks if the file at the specified file path exists and is not a directory. It uses os.Stat to get file information and checks if the file is not a directory.

Parameters: - filePath: string The path of the file to check.

Returns: - bool: true if the file exists and is not a directory, false otherwise.

func OpenFile

func OpenFile(filePath string, options ...*Options) (*os.File, error)

OpenFile opens a file at the specified file path with the given options. It wraps the createOrOpenFile function with specific flags for opening a file for appending and writing.

Parameters: - filePath: string The path of the file to open. - options: []*Options Optional parameters to specify file options.

Returns: - *os.File: The opened file. - error: An error if any occurred during the process.

func Permissions

func Permissions(filePath string, options ...*Options) error

Permissions sets the permissions of the file at the specified file path with the given options. It uses the resolveFileOptions function to determine the options and sets permissions accordingly.

Parameters: - filePath: string The path of the file to set permissions for. - options: []*Options Optional parameters to specify file options.

Returns: - error: An error if any occurred during the process.

func ReadFile

func ReadFile(filePath string) ([]byte, error)

ReadFile reads the content of the file at the specified file path. It uses os.ReadFile to read and return the content of the file.

Parameters: - filePath: string The path of the file to read.

Returns: - []byte: The content of the file. - error: An error if any occurred during the process.

func SHA1File

func SHA1File(filePath string) (string, error)

SHA1File calculates the SHA1 hash of the file at the specified file path. It opens the file, calculates its SHA1 hash, and returns the hash as a hex string.

Parameters: - filePath: string The path of the file to calculate the SHA1 hash for.

Returns: - string: The SHA1 hash of the file as a hex string. - error: An error if any occurred during the process.

func StatFile

func StatFile(filePath string) (fs.FileInfo, error)

StatFile returns the file information for the file at the specified file path. It calls os.Stat to retrieve file information.

Parameters: - filePath: string The path of the file to get information for.

Returns: - fs.FileInfo: The file information. - error: An error if any occurred during the process.

func WriteFile

func WriteFile(filePath string, content string) error

WriteFile writes the content to the file at the specified file path. It creates the necessary directory and then writes the content to the file using os.WriteFile.

Parameters: - filePath: string The path of the file to write to. - content: string The content to write to the file.

Returns: - error: An error if any occurred during the process.

Types

type Options

type Options struct {
	User  *user.User  // The user that owns the file.
	Perms fs.FileMode // The permissions for the file.
}

Options represents the options for file system storage. This struct holds the configuration for file or directory access and permissions.

Attributes: - User: *user.User The user that owns the file or directory. - Perms: fs.FileMode The permissions for the file or directory.

func (*Options) AddPerms

func (co *Options) AddPerms(perms fs.FileMode)

AddPerms adds the specified permissions to the current permissions of Options.

Parameters: - perms: fs.FileMode The permissions to add to the current set.

func (*Options) RemovePerms

func (co *Options) RemovePerms(perms fs.FileMode)

RemovePerms removes the specified permissions from the current permissions of Options.

Parameters: - perms: fs.FileMode The permissions to remove from the current set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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