Documentation ¶
Index ¶
- Variables
- func CleanPath(inputPath string) (string, error)
- func CleanPathOrDefault(inputPath string, defaultPath string) string
- func CopyFile(src, dst string) error
- func CountLines(filename string) (uint, error)
- func CountLinesWithOptions(reader io.Reader, separator []byte, filter func([]byte) bool) (uint, error)
- func CountLinesWithSeparator(separator []byte, filename string) (uint, error)
- func CreateFolder(path string) error
- func CreateFolders(paths ...string) error
- func DedupeLines(filename string) error
- func DeleteFilesOlderThan(folder string, filter FileFilters) error
- func DownloadFile(filepath string, url string) error
- func ExecutableName() string
- func FileExists(filename string) bool
- func FileExistsIn(file string, allowedPaths ...string) (string, error)
- func FileOrFolderExists(name string) bool
- func FileSizeToByteLen(fileSize string) (int, error)
- func FixMissingDirs(path string) error
- func FolderExists(foldername string) bool
- func GetTempFileName() (string, error)
- func HasPermission(fileName string, permission int) (bool, error)
- func HasStdin() bool
- func IsEmpty(filename string) (bool, error)
- func IsReadable(fileName string) (bool, error)
- func IsWriteable(fileName string) (bool, error)
- func Marshal(encodeType EncodeType, data []byte, obj interface{}) error
- func MarshalToWriter(encodeType EncodeType, r io.Writer, obj interface{}) error
- func OpenOrCreateFile(name string) (*os.File, error)
- func ReadFile(filename string) (chan string, error)
- func ReadFileWithBufferSize(filename string, maxCapacity int) (chan string, error)
- func ReadFileWithReader(r io.Reader) (chan string, error)
- func ReadFileWithReaderAndBufferSize(r io.Reader, maxCapacity int) (chan string, error)
- func RemoveAll(paths ...string) (errored map[string]error)
- func ResolveNClean(inputPath string, baseDir ...string) (string, error)
- func ResolveNCleanOrDefault(inputPath string, defaultPath string, baseDir ...string) string
- func SafeOpen(path string) (*os.File, error)
- func SafeOpenAppend(path string) (*os.File, error)
- func SafeOpenWrite(path string) (*os.File, error)
- func SafeWriteFile(path string, data []byte) error
- func SubstituteConfigFromEnvVars(filepath string) (io.Reader, error)
- func Unmarshal(encodeType EncodeType, data []byte, obj interface{}) error
- func UnmarshalFromReader(encodeType EncodeType, r io.Reader, obj interface{}) error
- func UseMusl(path string) (bool, error)
- type EncodeType
- type FileFilters
Constants ¶
This section is empty.
Variables ¶
var (
DefaultFilePermission = os.FileMode(0644)
)
var ErrInvalidSeparator = errors.New("invalid separator")
var IsNotEmpty = func(data []byte) bool { return len(data) > 0 }
IsNotEmpty determines if a data chunk is empty
var SkipEmptyLine = func(line []byte) bool { return len(line) > 0 }
Functions ¶
func CleanPath ¶
CleanPath cleans paths to migtigate any possible path traversal attacks. and it always returns an absolute path
func CleanPathOrDefault ¶
CleanPathOrDefault cleans paths to migtigate any possible path traversal attacks.
func CountLines ¶
CountLines counts the lines in a file
func CountLinesWithOptions ¶
func CountLinesWithOptions(reader io.Reader, separator []byte, filter func([]byte) bool) (uint, error)
CountLinesWithOptions from a reader and custom filter function
func CountLinesWithSeparator ¶
CountLinesWithSeparator of a file
func DedupeLines ¶
DedupeLines reads a file and removes duplicate lines from it. The function can be memory intensive for large files.
func DeleteFilesOlderThan ¶
func DeleteFilesOlderThan(folder string, filter FileFilters) error
func DownloadFile ¶
DownloadFile to specified path
func ExecutableName ¶
func ExecutableName() string
func FileExists ¶
FileExists checks if the file exists in the provided path
func FileExistsIn ¶
FileExistsIn checks if the file exists in the allowed paths
func FileOrFolderExists ¶
FileOrFolderExists checks if the file/folder exists
func FileSizeToByteLen ¶
FileSizeToByteLen converts a file size with units(kb, mb, gb, tb) to byte length e.g. 1kb -> 1024 If no unit is provided, it will fallback to mb. e.g: '2' will be converted to 2097152.
func FixMissingDirs ¶
FixMissingDirs creates any missing directories in chain /path/to/file
func FolderExists ¶
FolderExists checks if the folder exists
func GetTempFileName ¶
GetTempFileName generate a temporary file name
func HasPermission ¶
HasPermission checks if the file has the requested permission
func IsWriteable ¶
IsWriteable verify file writeability
func Marshal ¶
func Marshal(encodeType EncodeType, data []byte, obj interface{}) error
func MarshalToWriter ¶
func MarshalToWriter(encodeType EncodeType, r io.Writer, obj interface{}) error
func OpenOrCreateFile ¶
OpenOrCreate opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDWR. If there is an error, it'll create the named file with mode 0666. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError. Note: The file gets created only if the target directory exists
func ReadFileWithBufferSize ¶
ReadFile with filename and specific buffer size
func ReadFileWithReader ¶
ReadFileWithReader and stream on a channel
func ReadFileWithReaderAndBufferSize ¶
ReadFileWithReader with specific buffer size and stream on a channel
func ResolveNClean ¶
ResolveNClean resolves the path and cleans it ex: a nuclei template can be either abs or relative to a specified directory this function uses given path as a base to resolve the path instead of cwd
func ResolveNCleanOrDefault ¶
ResolveNCleanOrDefault resolves the path and cleans it
func SafeOpenAppend ¶
SafeOpenAppend opens a file after cleaning the path in append mode and creates any missing directories in chain /path/to/file
func SafeOpenWrite ¶
SafeOpenWrite opens a file after cleaning the path in write mode and creates any missing directories in chain /path/to/file
func SafeWriteFile ¶
SafeWriteFile writes data to a file after cleaning the path in write mode and creates any missing directories in chain /path/to/file
func SubstituteConfigFromEnvVars ¶
SubstituteConfigFromEnvVars reads a config file and generates a reader with substituted config values from environment variables
func Unmarshal ¶
func Unmarshal(encodeType EncodeType, data []byte, obj interface{}) error
func UnmarshalFromReader ¶
func UnmarshalFromReader(encodeType EncodeType, r io.Reader, obj interface{}) error