An open API service indexing awesome lists of open source software.

https://github.com/milwad-dev/filei

A golang file uploader package.
https://github.com/milwad-dev/filei

file file-uploader filei go go-file go-library go-package golang uploader

Last synced: over 1 year ago
JSON representation

A golang file uploader package.

Awesome Lists containing this project

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](https://godoc.org/github.com/milwad-devi/filei?status.svg)](https://pkg.go.dev/github.com/milwad-dev/filei)
[![Passed Tests](https://github.com/milwad-dev/filei/actions/workflows/tests.yml/badge.svg)](https://github.com/milwad-dev/filei/actions/workflows/tests.yml)

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:

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

## Usage

- [UploadFile](#upload-file)
- [GetFile](#get-file)
- [DeleteFile](#delete-file)
- [CreateFile](#create-file)
- [Exists](#exists)
- [CleanDirectory](#clean-directory)
- [DeleteDirectory](#delete-directory)
- [MoveFile](#move-file)
- [Files](#files)
- [Size](#size)
- [Chmod](#chmod)
- [Prepend](#prepend)
- [Append](#append)


### UploadFile

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

```go
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:

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


### DeleteFile

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

```go
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:

```go
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:

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


### CleanDirectory

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

```go
CleanDirectory("directory path") // Bool
```


### DeleteDirectory

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

```go
err := DeleteDirectory(directory)
```


### MoveDirectory

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

```go
err := MoveFile(sourcePath, destPath)
```


### Files

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

```go
files, err := Files(directory)
```


### Size

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

```go
size, err := Size(filePath)
```


### Chmod

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

```go
err := Chmod(filePath, 0700)
```


### Prepend

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

```go
err := Prepend(filePath, data)
```


# Append

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

```go
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](https://github.com/milwad-dev/filei/graphs/contributors)

## Security

If you've found a bug regarding security please mail [milwad.dev@gmail.com](mailto: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 :) ❤️

- Iraninan Gateway: https://daramet.com/milwad_khosravi
- Paypal Gateway: SOON
- MetaMask Address: `0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58`