miniofs

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

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

Go to latest
Published: Apr 15, 2025 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"
	"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.Open("text.txt")
	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 NewMinioFs

func NewMinioFs(ctx context.Context, dsn string) afero.Fs

func ParseURL

func ParseURL(minioURL string) (*minio.Options, error)

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 NewFs

func NewFs(ctx context.Context, client *minio.Client, bucket 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, openFlags int, fileMode os.FileMode, name string) *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)

Jump to

Keyboard shortcuts

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