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.
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.
For install the FileI
on your project, you can run below command on terminal:
go get -u github.com/milwad-dev/filei
- UploadFile
- GetFile
- DeleteFile
- CreateFile
- Exists
- CleanDirectory
- DeleteDirectory
- MoveFile
- Files
- Size
- Chmod
- Prepend
- Append
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 {
// ...
}
If you want to retrieve a file from the specified path, you can use GetFile
function:
file, err := GetFile("file path")
if err != nil {
// ...
}
If you want to delete a file, you can use DeleteFile
function:
err := DeleteFile("file path")
if err != nil {
// ...
}
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 {
// ...
}
If you want to ensure that a file exists, you can use Exists
function:
isExists := Exists("file path") // Bool
If you want to clean a directory (remove all files in a directory), you can use CleanDirectory
function:
CleanDirectory("directory path") // Bool
If you want to delete a directory, you can use DeleteDirectory
function:
err := DeleteDirectory(directory)
If you want to move a directory to another path, you can use MoveDirectory
function:
err := MoveFile(sourcePath, destPath)
If you want to get all files of a directory, you can use Files
function:
files, err := Files(directory)
If you want to get a size of a file, you can use Size
function:
size, err := Size(filePath)
If you want to give permission to a file, you can use Chmod
function:
err := Chmod(filePath, 0700)
If you want to write to the beginning of a file, you can use Prepend
function:
err := Prepend(filePath, data)
If you want to write to the end of a file, you can use Append
function:
err := Append(filePath, data)
- This package is created and modified by Milwad Khosravi for Laravel upper more than 9 and has been released under the MIT License.
This project exists thanks to all the people who contribute. CONTRIBUTING
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
If this package is helpful for you, you can buy a coffee for me :) ❤️
- Iraninan Gateway: https://daramet.com/milwad_khosravi
- Paypal Gateway: SOON
- MetaMask Address:
0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58