flysystem

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

go-flysystem

Go Report Card Go.Dev reference Sourcegraph Release

About Flysystem

Flysystem is a file storage library for Golang. It provides one interface to interact with many types of filesystems. When you use Flysystem, you're not only protected from vendor lock-in, you'll also have a consistent experience for which ever storage is right for you.

Install

$ go get github.com/pkg6/go-flysystem

Officially supported adapters

You can always create an adapter yourself.

type IAdapter interface {
    // DiskName Default Disk Name
	DiskName() string
	// Exists Determine if the file exists
	Exists(path string) (bool, error)
	// WriteReader write file content and return full path
	WriteReader(path string, reader io.Reader) (string, error)
	// Write  file content and return full path
	Write(path string, contents []byte) (string, error)
	// WriteStream Resource file write returns full path
	WriteStream(path, resource string) (string, error)
	// Read Read file
	Read(path string) ([]byte, error)
	// Delete  Deleting files returns the number of deleted files
	Delete(path string) (int64, error)
	// Size Get File Size
	Size(path string) (int64, error)
	// Update  the file content and return the updated full path
	Update(path string, contents []byte) (string, error)
	// UpdateStream Return the updated full path based on resource file updates
	UpdateStream(path, resource string) (string, error)
	// MimeType Get File MimeType
	MimeType(path string) (string, error)
	// Move move file
	Move(source, destination string) (bool, error)
	// Copy copy file
	Copy(source, destination string) (bool, error)
}

example

https://github.com/pkg6/go-flysystem/blob/main/.example/main.go

Documentation

Index

Constants

View Source
const (
	DiskNameLocal                   = "Local"
	DiskNameOSS                     = "ALiYunOSS"
	DiskNameCOS                     = "TencentCOS"
	DiskNameBOS                     = "BaiDuBOS"
	DiskNameGoogleCloudCloudStorage = "GoogleCloudCloudStorage"
	DiskNameQiNiuKoDo               = "QiNiuKoDo"

	PathTypeFile      = "file"
	PathTypeDirectory = "directory"
	ModePublicString  = "public"
	ModePrivateString = "private"
	ModeFilePublic    = 0644
	ModeFilePrivate   = 0600
	ModeDirPublic     = 0755
	ModeDirPrivate    = 0700
)

Variables

Functions

This section is empty.

Types

type AbstractAdapter

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

func (*AbstractAdapter) ApplyPathPrefix

func (a *AbstractAdapter) ApplyPathPrefix(path string) string

func (*AbstractAdapter) SetPathPrefix

func (a *AbstractAdapter) SetPathPrefix(prefix string)

type Flysystem

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

func (*Flysystem) Copy

func (f *Flysystem) Copy(source, destination string) (bool, error)

func (*Flysystem) Delete

func (f *Flysystem) Delete(path string) (int64, error)

func (*Flysystem) Disk

func (f *Flysystem) Disk(disk string) IFlysystem

func (*Flysystem) Exists

func (f *Flysystem) Exists(path string) (bool, error)

func (*Flysystem) Extend

func (f *Flysystem) Extend(adapter IAdapter, names ...string) IFlysystem

Extend 扩展

func (*Flysystem) FindAdapter

func (f *Flysystem) FindAdapter() IAdapter

FindAdapter Find Adapter

func (*Flysystem) MimeType

func (f *Flysystem) MimeType(path string) (string, error)

func (*Flysystem) Move

func (f *Flysystem) Move(source, destination string) (bool, error)

func (*Flysystem) Read

func (f *Flysystem) Read(path string) ([]byte, error)

func (*Flysystem) Size

func (f *Flysystem) Size(path string) (int64, error)

func (*Flysystem) Update

func (f *Flysystem) Update(path string, contents []byte) (string, error)

func (*Flysystem) UpdateStream

func (f *Flysystem) UpdateStream(path, resource string) (string, error)

func (*Flysystem) Write

func (f *Flysystem) Write(path string, contents []byte) (string, error)

func (*Flysystem) WriteReader added in v0.0.2

func (f *Flysystem) WriteReader(path string, reader io.Reader) (string, error)

func (*Flysystem) WriteStream

func (f *Flysystem) WriteStream(path, resource string) (string, error)

type IAdapter

type IAdapter interface {
	IFS
	// DiskName Default Disk Name
	DiskName() string
}

type IFS

type IFS interface {
	// Exists Determine if the file exists
	Exists(path string) (bool, error)
	// WriteReader write file content and return full path
	WriteReader(path string, reader io.Reader) (string, error)
	// Write  file content and return full path
	Write(path string, contents []byte) (string, error)
	// WriteStream Resource file write returns full path
	WriteStream(path, resource string) (string, error)
	// Read Read file
	Read(path string) ([]byte, error)
	// Delete  Deleting files returns the number of deleted files
	Delete(path string) (int64, error)
	// Size Get File Size
	Size(path string) (int64, error)
	// Update  the file content and return the updated full path
	Update(path string, contents []byte) (string, error)
	// UpdateStream Return the updated full path based on resource file updates
	UpdateStream(path, resource string) (string, error)
	// MimeType Get File MimeType
	MimeType(path string) (string, error)
	// Move move file
	Move(source, destination string) (bool, error)
	// Copy copy file
	Copy(source, destination string) (bool, error)
}

type IFlysystem

type IFlysystem interface {
	IFS
	Extend(adapter IAdapter, names ...string) IFlysystem
	Disk(disk string) IFlysystem
	FindAdapter() IAdapter
}

func New

func New() IFlysystem

func NewAdapters

func NewAdapters(adapters ...IAdapter) IFlysystem

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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