files

package
v0.0.0-...-ee9e2bb Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultOpenFlag = os.O_CREATE | os.O_WRONLY | os.O_TRUNC
View Source
const MAX_BYTES_TO_READ = 2 * 1024 // 2KB buffer to read file
View Source
const TrimCutSet = " \n\r"

Variables

View Source
var (
	// FilesCSVFilter is a filter function for csv extension files
	FilesCSVFilter = GetExtensionFilter("csv")
	// FilesJSONFilter is a filter function for json extension files
	FilesJSONFilter = GetExtensionFilter("json")
)

Common filters

Functions

func CheckAndMakeDir

func CheckAndMakeDir(dpath string) error

CheckAndMakeDir check if the directory exists and creates it with all its tree structure if not.

func FileCompare

func FileCompare(fpath1, fpath2 string) (bool, error)

FileCompare return true if the files have the same content (byte to byte), false otherwize with an error indicating the differences

func FileCompareToString

func FileCompareToString(fpath, str string, trim bool) (bool, error)

func FileContent

func FileContent(fpath string, trim bool) (string, error)

FileContent returns the content of the file as a string (the content is supposed to be a readable text). If trim is true then the string is trimmed by left and right from unexpected characters space, \n and \r.

func ListFilenames

func ListFilenames(dirpath string) ([]string, error)

ListFilenames returns the names of files in dirpath (no filter)

func ListFilenamesWithFilter

func ListFilenamesWithFilter(dirpath string, filter FilesFilterFunc) ([]string, error)

ListFilenamesWithFilter returns the names of files in dirpath that satisfy the filter

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the path exists, and false otherwize. In the case where the file is considered as not existing, the err can help you to check the actual reason (maybe it exists but can not be reached). Even if the file exists, there could have an error, then check bool AND error results.

Types

type CSVDataSet

type CSVDataSet []map[string]string

func CSVload

func CSVload(csvpath string) (CSVDataSet, error)

CSVload loads the data from this CSV file. The data are return as a list of maps corresponding for each row to a map whose keys are the column names and values the column values.

func CSVread

func CSVread(reader io.Reader) (CSVDataSet, error)

CSVread reads this CSV stream and returns a list of maps corresponding for each row to a map whose keys are the column names and values the column values.

type FileType

type FileType string
const (
	FTYPE_UNDEF FileType = "unknown"
	FTYPE_PDF   FileType = "PDF document"
	FTYPE_PNG   FileType = "PNG image data"
	FTYPE_GIF   FileType = "GIF image data"
	FTYPE_JPEG  FileType = "JPEG image data"
	FTYPE_OGG   FileType = "Ogg data"
	FTYPE_WAV   FileType = "WAV audio"
)

func GetFileType

func GetFileType(fpath string) (ftype FileType, err error)

GetFileType returns the content type of the file, as the shell command file would return. The type is determined by analysing the header content of the file.

func (FileType) Equals

func (ft FileType) Equals(other FileType) bool

func (FileType) String

func (ft FileType) String() string

type FileWriter

type FileWriter struct {
	*bufio.Writer
	// contains filtered or unexported fields
}

FileWriter returns a buffer writer to a given file

func NewFileWriter

func NewFileWriter(fpath string) (*FileWriter, error)

NewFileWriter is an execution of NewFileWriterWithFlag with the default flag

func NewFileWriterWithFlag

func NewFileWriterWithFlag(fpath string, flag int) (*FileWriter, error)

NewFileWriterWithFlag open a writer to the output file specified by path. If the directory containing this path does not exist, then it tries to create it.

func (FileWriter) Close

func (w FileWriter) Close() error

type FilesFilterFunc

type FilesFilterFunc func(info os.FileInfo) bool

FilesFilterFunc represents a function used to filter files by name

func GetExtensionFilter

func GetExtensionFilter(ext string) FilesFilterFunc

GetExtensionFilter returns a FilesFilterFunc that can be used to filter files with the specified extension

Jump to

Keyboard shortcuts

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