interfaces

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessor

type Accessor interface {
	Metadata() Metadata

	// Create
	//
	// # Behavior
	// 	 - Input path MUST match with object.ObjectMode, WITHOUT checking ObjectMode.
	// 	 - Creating on existing dir SHOULD succeed.
	// 	 - Creating on existing file SHOULD overwrite and truncate.
	Create(ctx context.Context, path string, args options.CreateOptions) error

	// Read returns [io.ReadCloser] if operation succeeded
	//
	// # Behavior
	// 	 - Input path MUST match with object.ObjectMode, WITHOUT checking ObjectMode.
	Read(ctx context.Context, path string, args options.ReadOptions) (io.ReadCloser, error)

	// Write returns written size if operation succeeded
	//
	// # Behavior
	// 	 - Input path MUST be file path, WITHOUT checking ObjectMode.
	Write(ctx context.Context, path string, args options.WriteOptions, reader io.ReadSeeker) (uint64, error)

	// Stat
	//
	//	- Stat an empty path means stat provider's root path.
	// 	- Stat a path ends-with "/" means stating a dir.
	// 	- `mode` and `content_length` must be set.
	Stat(ctx context.Context, path string, args options.StatOptions) (ObjectMetadata, error)

	// Delete
	//
	// # Behavior
	//
	// 	- it is an idempotent operation, it's safe to call `Delete` on the same path multiple times.
	// 	- it SHOULD return nil if the path is deleted successfully or not exist.
	Delete(ctx context.Context, path string, args options.DeleteOptions) error

	// List
	//
	// # Behavior
	//
	//  - Input path MUST be dir path, DON'T NEED to check ObjectMode.
	//  - List non-exist dir should return Empty.
	List(ctx context.Context, path string, args options.ListOptions) (ObjectStream, error)

	// PreSign
	//
	// # Behavior
	//
	//	- Requires capability: `PreSign`
	// 	- This API is optional, throws errors.ErrUnsupportedMethod if not supported.
	PreSign(ctx context.Context, path string, args options.PreSignOptions) (*http.Request, error)

	// CreateMultipart
	//
	// # Behavior
	//
	//  - Requires capability: `Multipart`
	// 	- This op returns a `upload_id` which is required to for following APIs.
	CreateMultipart(ctx context.Context, path string, args options.CreateMultipart) (string, error)

	// WriteMultipart
	//
	// # Behavior
	//
	//  - Requires capability: `Multipart`
	WriteMultipart(ctx context.Context, path string, args options.WriteMultipart, reader io.ReadSeeker) (ObjectPart, error)

	// CompleteMultipart
	// # Behavior
	//
	//  - Requires capability: `Multipart`
	CompleteMultipart(ctx context.Context, path string, args options.CompleteMultipart) error

	// AbortMultipart
	// # Behavior
	//
	//  - Requires capability: `Multipart`
	AbortMultipart(ctx context.Context, path string, args options.AbortMultipart) error
}

type Capability

type Capability uint8
const (
	// Read `read` and `stat`
	Read Capability = 1 << iota

	// Write `write` and `delete`
	Write

	// List `list`
	List

	// PreSign `preSign`
	PreSign

	// Multipart `multipart`
	Multipart

	// Blocking `blocking`
	Blocking
)

func (Capability) CapString added in v0.0.2

func (c Capability) CapString() string

func (Capability) Has

func (c Capability) Has(capabilities ...Capability) bool

func (Capability) String added in v0.0.2

func (c Capability) String() string

type Entry

type Entry interface {
	Accessor() Accessor
	Path() string
	Metadata() ObjectMetadata
	IsComplete() bool
}

type Layer added in v0.0.2

type Layer func(Accessor) Accessor

type Metadata

type Metadata interface {
	Provider() Provider
	Root() string
	Name() string
	Capability() Capability
	String() string
}

type Object

type Object interface {
	GetAccessor() Accessor
	GetPath() string
}

type ObjectMetadata

type ObjectMetadata interface {
	Mode() ObjectMode
	ContentLength() *uint64
	ContentMD5() *string
	LastModified() *time.Time
	ETag() *string
}

type ObjectMode

type ObjectMode int8
const (
	Unknown ObjectMode = iota
	FILE
	DIR
)

func ObjectModeFromPath

func ObjectModeFromPath(path string) ObjectMode

func (ObjectMode) IsDir

func (m ObjectMode) IsDir() bool

func (ObjectMode) IsFile

func (m ObjectMode) IsFile() bool

func (ObjectMode) String

func (m ObjectMode) String() string

type ObjectPageStream

type ObjectPageStream interface {
	NextPage(ctx context.Context) ([]Entry, error)
}

type ObjectPart

type ObjectPart interface {
	GetPartNumber() uint
	GetETag() string
}

type ObjectStream

type ObjectStream interface {
	HasNext() bool
	Next(ctx context.Context) (Entry, error)
}

type Operation added in v0.0.2

type Operation int
const (
	MetadataOP Operation = iota + 1
	CreateOp
	ReadOp
	WriteOp
	StatOp
	DeleteOp
	ListOp
	PreSignOp
	CreateMultipartOp
	WriteMultipartOp
	CompleteMultipartOp
	AbortMultipartOp
)

func (Operation) String added in v0.0.2

func (o Operation) String() string

type Provider

type Provider int
const (
	S3 Provider = iota + 1
	Fs
)

func (Provider) String

func (p Provider) String() string

Jump to

Keyboard shortcuts

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