minio

package module
v0.0.0-...-e64ea66 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

README

minio sdk for afero

Go Report Card GoDoc

About

It provides an afero filesystem implementation of a MinIO.

This was created to provide a backend to the MinIO server but can definitely be used in any other code.

I'm very opened to any improvement through issues or pull-request that might lead to a better implementation or even better testing.

Key points

  • Download & upload file streaming
  • Very carefully linted

Known limitations

  • File appending / seeking for write is not supported because MinIO doesn't support it, it could be simulated by rewriting entire files.
  • Chtimes is not supported because MinIO doesn't support it, it could be simulated through metadata.
  • Chmod support is very limited

How to use

import (
    "context"
    
    "github.com/minio/minio-go/v7"
	miniofs "github.com/cpyun/afero-minio"
)

func main() {
    minioClient := minio.New(endpoint, &opts)

	// Initialize the MinIOFS
    fs := miniofs.NewMinioFs(context.Background(), minioClient)
    
	// And use it
	file, _ := fs.OpenFile("text.txt", os.O_WRONLY, 0777)
	defer file.Close()
	file.WriteString("Hello world.")
}

Thanks

License

Afero is released under the Apache 2.0 license. See LICENSE.txt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBucketInName  = errors.New("no bucket name found in the name")
	ErrEmptyObjectName = errors.New("storage: object name is empty")
	ErrFileClosed      = os.ErrClosed
	ErrOutOfRange      = errors.New("out of range")
	ErrNotSupported    = errors.New("doesn't support this operation")
)

Functions

func NewMinio

func NewMinio(ctx context.Context, client *minio.Client, bucket string) afero.Fs

Types

type ByName

type ByName []*FileInfo

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (fi *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (fi *FileInfo) Mode() os.FileMode

func (*FileInfo) Name

func (fi *FileInfo) Name() string

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

func (*FileInfo) Sys

func (fi *FileInfo) Sys() interface{}

type Fs

type Fs struct {
	// contains filtered or unexported fields
}

Fs is a Fs implementation that uses functions provided by google cloud storage

func NewMinioFs

func NewMinioFs(ctx context.Context, client *minio.Client) *Fs

func NewMinioFsWithSeparator

func NewMinioFsWithSeparator(ctx context.Context, client *minio.Client, folderSep string) *Fs

func (*Fs) Chmod

func (fs *Fs) Chmod(_ string, _ os.FileMode) error

func (*Fs) Chown

func (fs *Fs) Chown(_ string, _, _ int) error

func (*Fs) Chtimes

func (fs *Fs) Chtimes(_ string, _, _ time.Time) error

func (*Fs) Create

func (fs *Fs) Create(name string) (afero.File, error)

func (*Fs) Mkdir

func (fs *Fs) Mkdir(name string, _ os.FileMode) error

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(_ string, _ os.FileMode) error

func (*Fs) Name

func (fs *Fs) Name() string

func (*Fs) Open

func (fs *Fs) Open(name string) (afero.File, error)

func (*Fs) OpenFile

func (fs *Fs) OpenFile(name string, flag int, fileMode os.FileMode) (afero.File, error)

func (*Fs) Remove

func (fs *Fs) Remove(name string) error

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(path string) error

func (*Fs) Rename

func (fs *Fs) Rename(oldName, newName string) error

func (*Fs) Stat

func (fs *Fs) Stat(name string) (os.FileInfo, error)

type MinioFile

type MinioFile struct {
	// contains filtered or unexported fields
}

MinioFile is the Afero version adapted for Minio

func NewMinioFile

func NewMinioFile(ctx context.Context, fs *Fs, bucket *minio.BucketInfo, openFlags int,

	fileMode os.FileMode,
	name string,
) *MinioFile

func NewMinioFileFromOldFH

func NewMinioFileFromOldFH(openFlags int, fileMode os.FileMode, oldFile *minioFileResource) *MinioFile

func (*MinioFile) Close

func (o *MinioFile) Close() error

func (*MinioFile) Name

func (o *MinioFile) Name() string

func (*MinioFile) Read

func (o *MinioFile) Read(p []byte) (n int, err error)

func (*MinioFile) ReadAt

func (o *MinioFile) ReadAt(p []byte, off int64) (n int, err error)

func (*MinioFile) Readdir

func (o *MinioFile) Readdir(count int) ([]os.FileInfo, error)

func (*MinioFile) Readdirnames

func (o *MinioFile) Readdirnames(n int) ([]string, error)

func (*MinioFile) Seek

func (o *MinioFile) Seek(newOffset int64, whence int) (int64, error)

func (*MinioFile) Stat

func (o *MinioFile) Stat() (os.FileInfo, error)

func (*MinioFile) Sync

func (o *MinioFile) Sync() error

func (*MinioFile) Truncate

func (o *MinioFile) Truncate(wantedSize int64) error

func (*MinioFile) Write

func (o *MinioFile) Write(p []byte) (n int, err error)

func (*MinioFile) WriteAt

func (o *MinioFile) WriteAt(b []byte, off int64) (n int, err error)

func (*MinioFile) WriteString

func (o *MinioFile) WriteString(s string) (ret int, err error)

type MinioFs

type MinioFs struct {
	// contains filtered or unexported fields
}

func (*MinioFs) Chmod

func (fs *MinioFs) Chmod(name string, mode os.FileMode) error

func (*MinioFs) Chown

func (fs *MinioFs) Chown(name string, uid, gid int) error

func (*MinioFs) Chtimes

func (fs *MinioFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*MinioFs) Create

func (fs *MinioFs) Create(name string) (afero.File, error)

func (*MinioFs) Mkdir

func (fs *MinioFs) Mkdir(name string, perm os.FileMode) error

func (*MinioFs) MkdirAll

func (fs *MinioFs) MkdirAll(path string, perm os.FileMode) error

func (*MinioFs) Name

func (fs *MinioFs) Name() string

func (*MinioFs) Open

func (fs *MinioFs) Open(name string) (afero.File, error)

func (*MinioFs) OpenFile

func (fs *MinioFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

func (*MinioFs) Remove

func (fs *MinioFs) Remove(name string) error

func (*MinioFs) RemoveAll

func (fs *MinioFs) RemoveAll(path string) error

func (*MinioFs) Rename

func (fs *MinioFs) Rename(oldname, newname string) error

func (*MinioFs) Stat

func (fs *MinioFs) Stat(name string) (os.FileInfo, error)

Jump to

Keyboard shortcuts

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