filei

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 6 Imported by: 0

README

FileI

The FileI is a lightweight and easy-to-use package for handling file operations in Go (Golang). It simplifies common file-related tasks such as uploading, deleting, and managing files, allowing developers to handle file I/O operations with minimal effort. Whether you're building an API, managing assets, or simply need a streamlined way to work with files in Go, FileI provides intuitive methods that integrate seamlessly into your project.

GoDoc Widget Passed Tests

Key Features:

  • File Upload: Easily upload files with minimal configuration.
  • File Deletion: Remove files from your system with a single function call.
  • Error Handling: Provides built-in error handling for common file operations.
  • Cross-platform Support: Works across different operating systems.

Perfect for developers who need to manage file operations quickly and efficiently in their Go projects.

Installation

For install the FileI on your project, you can run below command on terminal:

go get -u github.com/milwad-dev/filei

Usage

UploadFile

If you want to upload a file to a path you can use UploadFile function:

file, _ := os.Create("testdata/new-text.txt")

err := UploadFile(file, "destPath")
if err != nil {
    // ...
}

GetFile

If you want to retrieve a file from the specified path, you can use GetFile function:

file, err := GetFile("file path")
if err != nil {
	// ...
}

DeleteFile

If you want to delete a file, you can use DeleteFile function:

err := DeleteFile("file path")
if err != nil {
    // ...
}

CreateFile

If you want to create a file with specific extension and contains a data, you can use CreateFile function:

data := []byte("milwad")

err := CreateFile("file path", data)
if err != nil {
    // ...
}

Exists

If you want to ensure that a file exists, you can use Exists function:

isExists := Exists("file path") // Bool

CleanDirectory

If you want to clean a directory (remove all files in a directory), you can use CleanDirectory function:

CleanDirectory("directory path") // Bool

DeleteDirectory

If you want to delete a directory, you can use DeleteDirectory function:

err := DeleteDirectory(directory)

MoveDirectory

If you want to move a directory to another path, you can use MoveDirectory function:

err := MoveFile(sourcePath, destPath)

Files

If you want to get all files of a directory, you can use Files function:

files, err := Files(directory)

Size

If you want to get a size of a file, you can use Size function:

size, err := Size(filePath)

Chmod

If you want to give permission to a file, you can use Chmod function:

err := Chmod(filePath, 0700)

Prepend

If you want to write to the beginning of a file, you can use Prepend function:

err := Prepend(filePath, data)

Append

If you want to write to the end of a file, you can use Append function:

err := Append(filePath, data)

License

  • This package is created and modified by Milwad Khosravi for Laravel upper more than 9 and has been released under the MIT License.

Contributing

This project exists thanks to all the people who contribute. CONTRIBUTING

Security

If you've found a bug regarding security please mail milwad.dev@gmail.com instead of using the issue tracker.

Donate

If this package is helpful for you, you can buy a coffee for me :) ❤️

Iranian Gateway: https://daramet.com/milwad_khosravi Paypal Gateway: SOON

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v1.0.0

func Append(filePath string, data string) error

Append write to the end of a file.

func Chmod added in v0.7.0

func Chmod(filePath string, mode os.FileMode) error

Chmod give permission to a file.

func CleanDirectory added in v0.4.0

func CleanDirectory(directory string) bool

CleanDirectory clear the directory.

func CreateFile

func CreateFile(filaName string, data []byte) error

CreateFile create a new file from the specified path and data.

func DeleteDirectory added in v0.4.0

func DeleteDirectory(directory string) error

DeleteDirectory delete the directory.

func DeleteFile

func DeleteFile(fileName string) error

DeleteFile removes a file from the specified path.

func Exists added in v0.3.0

func Exists(fileName string) bool

Exists ensure that the file exists.

func Files added in v0.5.0

func Files(directoryPath string) ([]os.DirEntry, error)

Files get the list of files of a directory.

func GetFile

func GetFile(fileName string) (multipart.File, error)

GetFile retrieve a file from the specified path.

func MoveFile added in v0.5.0

func MoveFile(sourcePath, destPath string) error

MoveFile move the file from one place to another place.

func Prepend added in v0.9.0

func Prepend(filePath string, data string) error

Prepend write to the beginning of a file.

func Size added in v0.6.0

func Size(filePath string) (int64, error)

Size get the size of a file.

func UploadFile

func UploadFile(file multipart.File, fileName string) error

UploadFile saves an uploaded file to the specified path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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