fsutil

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 5 Imported by: 2 modules, 4 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.

README

fsutil

Go Reference Go Report Card Actions Status codecov

Package fsutil provides a collection of utility functions that extend the capabilities of the Go standard filesystem package. It offers a variety of tools for working with files and directories, making it easier to perform common filesystem operations.

Installation

go get github.com/shelepuginivan/fsutil

Documentation

Is available on pkg.go.dev

Documentation

Overview

Package fsutil provides a collection of utility functions that extend the capabilities of the Go standard filesystem (fs) package. It offers a variety of tools for working with files and directories, making it easier to perform common filesystem operations.

This package is designed to enhance the functionality of the standard library by providing additional features and abstractions. It is particularly useful for developers looking to simplify their filesystem interactions in Go applications.

Index

Constants

View Source
const (
	CR = "\r" // Caret return.
	LF = "\n" // Line break.
)
View Source
const NewLine = LF // Platform-specific newline character.

Variables

This section is empty.

Functions

func AssertDirExists

func AssertDirExists(path string)

AssertDirExists panics if path does not exist or is not a directory.

func AssertFileExists

func AssertFileExists(path string)

AssertFileExists panics if path does not exist or is not a file.

func AssertPathExists

func AssertPathExists(path string)

AssertPathExists panics if path does not exist.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies file src to file dst. It does not support recursive copying.

func CreateAll

func CreateAll(file string) (*os.File, error)

CreateAll creates file and all its parent directories. If the file exists, it is truncated.

func DirExists

func DirExists(path string) bool

DirExists reports whether path exists and is a directory.

func FileExists

func FileExists(path string) bool

FileExists reports whether path exists and is a file.

func Must

func Must[T any](v T, err error) T

Must is a helper that wraps a call to a function returning an error and panics if the error is not nil. It is intended for use in variable initialization.

func PathExists

func PathExists(path string) bool

PathExists reports whether path exists.

func ReadLines

func ReadLines(path string) (lines []string, err error)

ReadLines reads a file and returns its content as a slice of strings.

func ReadString

func ReadString(path string) (string, error)

ReadString reads path and returns its content as string.

func RemoveAllIfExists

func RemoveAllIfExists(path string) error

RemoveAllIfExists is like os.RemoveAll except that it returns an error if the path does not exist.

func WriteAll

func WriteAll(path string, data []byte, perm ...fs.FileMode) error

WriteAll writes data to path, creating all necessary parent directories. If parent directories already exist, WriteAll does nothing to them. If file already exists, it is overwritten with the given data.

Permission perm is optional and defaults to os.ModePerm.

func WriteLines

func WriteLines(path string, content []string, perm ...fs.FileMode) error

WriteLines writes a slice of string as lines to a file.

WriteLines uses platform-specific linebreak character (LF on Unix, CRLF of Windows). Use WriteLinesWithNewlineChar if specific newline character is required.

Permission perm is optional and defaults to os.ModePerm.

func WriteLinesWithNewlineChar

func WriteLinesWithNewlineChar(path string, content []string, newline string, perm ...fs.FileMode) error

WriteLinesWithNewlineChar is like WriteLines, but allows to set newline character used.

func WriteString

func WriteString(path, content string, perm ...fs.FileMode) error

WriteString writes a string content to a file.

Permission perm is optional and defaults to os.ModePerm.

Types

This section is empty.

Jump to

Keyboard shortcuts

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