ef

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

ef

Easy Files - a library that makes working with files in Go enjoyable.

Install

go get github.com/alexcoder04/ef

Use

package main

import (
    ...

    "github.com/alexcoder04/ef
)

func main(){
    f := ef.NewFile("assets", "image.png")
    if !f.Exists {
        println("file does not exist")
        return
    }

    println(f.PathAbs())

    err := f.Copy("new/image.png")
    if err != nil {
        ...
    }
}

Documentation

Please refer to pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrInvalidFile

type ErrInvalidFile struct{}

Error returned when an operation cannot be executed on the given file type.

func (*ErrInvalidFile) Error

func (e *ErrInvalidFile) Error() string

type File

type File struct {
	Path string
}

File type describes a file. It may be a directory, regular or even non-existent file.

func NewFile

func NewFile(pathPaths ...string) File

Creates a new File object. All passed arguments are joined into one file path.

func (*File) Append

func (f *File) Append(data []byte) error

Appends bytes to a file. Is it doesn't exists, creates it.

func (*File) AppendLines

func (f *File) AppendLines(data []string) error

Appends a list of strings representing lines to a file. Is it doesn't exists, creates it.

func (*File) AppendString

func (f *File) AppendString(data string) error

Appends a string to a file. Is it doesn't exists, creates it.

func (*File) Copy

func (f *File) Copy(destin string) error

Copies the file to a new destination. Works with both files and directories.

func (*File) Exists

func (f *File) Exists() (bool, error)

Returns true if the file exists.

func (*File) IsDir

func (f *File) IsDir() (bool, error)

Returns true if file is a directory.

func (*File) IsRegular

func (f *File) IsRegular() (bool, error)

Returns true if file is a regular file.

func (*File) List

func (f *File) List() ([]File, error)

Lists all files inside the directory (if the file is a directory, otherwise throws an error).

func (*File) Move

func (f *File) Move(destin string) error

Copies the file to a new destination. Works with both files and directories.

func (*File) Name

func (f *File) Name() string

Returns the base name of the file.

func (*File) PathAbs

func (f *File) PathAbs() (string, error)

Returns the absolute path of the file.

func (*File) PathAbsResolved

func (f *File) PathAbsResolved() (string, error)

Resolves any symlinks in the absolute path of the file.

func (*File) PathResolved

func (f *File) PathResolved() (string, error)

Resolves any symlinks in the file path.

func (*File) Permissions

func (f *File) Permissions() (fs.FileMode, error)

Returns the file permissions.

func (*File) Read

func (f *File) Read() ([]byte, error)

Reads and returns the content of the file as bytes.

func (*File) ReadLines

func (f *File) ReadLines() ([]string, error)

Reads and returns the content of a file as a list of strings representing the lines.

func (*File) ReadString

func (f *File) ReadString() (string, error)

Reads and returns the content of the file as a string.

func (*File) Write

func (f *File) Write(data []byte) error

Writes bytes into a file. Overwrites any existing data.

func (*File) WriteLines

func (f *File) WriteLines(data []string) error

Writes a list of strings into a file as lines. Overwrites any existing data.

func (*File) WriteString

func (f *File) WriteString(data string) error

Writes a string into a file. Overwrites any existing data.

Jump to

Keyboard shortcuts

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