Documentation ¶
Index ¶
- func Contains(filePath string, substring string) (bool, error)
- func CreateDirectory(dirPath string, options ...*Options) error
- func CreateFile(filePath string, options ...*Options) (*os.File, error)
- func DeleteDirectory(dirPath string) error
- func DeleteFile(filePath string) error
- func ExistsDirectory(dirPath string) bool
- func ExistsFile(filePath string) bool
- func OpenFile(filePath string, options ...*Options) (*os.File, error)
- func Permissions(filePath string, options ...*Options) error
- func ReadFile(filePath string) ([]byte, error)
- func SHA1File(filePath string) (string, error)
- func StatFile(filePath string) (fs.FileInfo, error)
- func WriteFile(filePath string, content string) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RemovePerms removes the specified permissions from the current permissions of Options.
Parameters: - perms: fs.FileMode The permissions to remove from the current set.