Skip to content

milwad-dev/filei

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 [email protected] instead of using the issue tracker.

Donate

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