storage

package
v0.0.0-...-2ddd709 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewS3StaticCreds

func NewS3StaticCreds(accessID, secretKey string) *credentials.Credentials

NewS3StaticCreds returns a simple static credentials object

Types

type FileBuffer

type FileBuffer struct {
	// Buff is the backing buffer
	Buff *bytes.Buffer
	// Index indicates where in the buffer we are at
	Index int64
	// contains filtered or unexported fields
}

FileBuffer implements interfaces implemented by files. The main purpose of this type is to have an in memory replacement for a file.

func New

func New(b []byte) *FileBuffer

New returns a new populated Buffer

func NewFromReader

func NewFromReader(reader io.Reader) (*FileBuffer, error)

NewFromReader is a convenience method that returns a new populated Buffer whose contents are sourced from a supplied reader by loading it entirely into memory.

func (*FileBuffer) Bytes

func (f *FileBuffer) Bytes() []byte

Bytes returns the bytes available until the end of the buffer.

func (*FileBuffer) Close

func (f *FileBuffer) Close() error

Close implements io.Closer https://golang.org/pkg/io/#Closer It closes the buffer, rendering it unusable for I/O. It returns an error, if any.

func (*FileBuffer) Read

func (f *FileBuffer) Read(b []byte) (n int, err error)

When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. An instance of this general case is that a Reader returning a non-zero number of bytes at the end of the input stream may return either err == EOF or err == nil. The next Read should return 0, EOF.

func (*FileBuffer) ReadAt

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

ReadAt implements io.ReaderAt https://golang.org/pkg/io/#ReaderAt ReadAt reads len(p) bytes into p starting at offset off in the underlying input source. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.

When ReadAt returns n < len(p), it returns a non-nil error explaining why more bytes were not returned. In this respect, ReadAt is stricter than Read.

Even if ReadAt returns n < len(p), it may use all of p as scratch space during the call. If some data is available but not len(p) bytes, ReadAt blocks until either all the data is available or an error occurs. In this respect ReadAt is different from Read.

If the n = len(p) bytes returned by ReadAt are at the end of the input source, ReadAt may return either err == EOF or err == nil.

If ReadAt is reading from an input source with a seek offset, ReadAt should not affect nor be affected by the underlying seek offset. Clients of ReadAt can execute parallel ReadAt calls on the same input source.

func (*FileBuffer) Reopen

func (f *FileBuffer) Reopen() error

Reopen is just a utility to reaccess the buffer after it's been closed.

func (*FileBuffer) Reset

func (f *FileBuffer) Reset() error

Reset will discard the data buffer

func (*FileBuffer) Seek

func (f *FileBuffer) Seek(offset int64, whence int) (idx int64, err error)

Seek implements io.Seeker https://golang.org/pkg/io/#Seeker

func (*FileBuffer) String

func (f *FileBuffer) String() string

String implements the Stringer interface

func (*FileBuffer) Write

func (f *FileBuffer) Write(p []byte) (n int, err error)

Write implements io.Writer https://golang.org/pkg/io/#Writer by appending the passed bytes to the buffer unless the buffer is closed or index negative.

type FileSystemService

type FileSystemService struct {
	RootDirectory string
}

FileSystemService is a storage backend for local filesystem storage

func NewFileSystemService

func NewFileSystemService(rootDirectory string) *FileSystemService

NewFileSystemService creates a new instance of LocalFilesystemBackend

func (*FileSystemService) DeleteObject

func (s *FileSystemService) DeleteObject(ctx context.Context, path string) error

DeleteObject removes an object from root directory

func (*FileSystemService) GetObject

func (s *FileSystemService) GetObject(ctx context.Context, path string) (*Object, error)

GetObject retrieves an object from root directory

func (*FileSystemService) ListObjects

func (s *FileSystemService) ListObjects(ctx context.Context, prefix string) ([]*Object, error)

ListObjects lists all objects in root directory (depth 1)

func (*FileSystemService) PutObject

func (s *FileSystemService) PutObject(ctx context.Context, path string, content io.Reader) error

PutObject puts an object in root directory

type Object

type Object struct {
	Path         string
	Content      io.ReadCloser
	ETag         string
	ContentType  string
	Size         int64
	LastModified time.Time
}

Object is a generic representation of a storage object

func (*Object) Close

func (o *Object) Close() error

Close closes the content ReadCloser

func (*Object) HasExtension

func (o *Object) HasExtension(extension string) bool

HasExtension determines whether or not an object contains a file extension

func (*Object) Read

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

Read readers the content

type S3Options

type S3Options struct {
	Creds  *credentials.Credentials
	Region string
	Prefix string
	Secure bool
	ACL    string
}

S3Options is a struct to hold service options

type S3Service

type S3Service struct {
	Bucket string
	Client *minio.Client
	Prefix string
	// contains filtered or unexported fields
}

S3Service is a storage backend for Amazon S3

func NewS3Service

func NewS3Service(endpoint, bucket string, opts *S3Options) (*S3Service, error)

NewS3Service creates a new instance of S3Service

func (*S3Service) DeleteObject

func (s *S3Service) DeleteObject(ctx context.Context, path string) error

DeleteObject removes an object from Amazon S3 compat bucket, at prefix

func (*S3Service) GetObject

func (s *S3Service) GetObject(ctx context.Context, path string) (*Object, error)

GetObject retrieves an object from Amazon S3 compat bucket, at prefix

func (*S3Service) ListObjects

func (s *S3Service) ListObjects(ctx context.Context, prefix string) ([]*Object, error)

ListObjects lists all objects in Amazon S3 compat bucket, at prefix

func (*S3Service) PutObject

func (s *S3Service) PutObject(ctx context.Context, path string, content io.Reader) error

PutObject uploads an object to Amazon S3 compat bucket, at prefix

func (*S3Service) SetACL

func (s *S3Service) SetACL(acl string) error

SetACL sets the s3 acl header to be used for future ops.

type Service

type Service interface {
	ListObjects(ctx context.Context, prefix string) ([]*Object, error)
	GetObject(ctx context.Context, path string) (*Object, error)
	PutObject(ctx context.Context, path string, content io.Reader) error
	DeleteObject(ctx context.Context, path string) error
}

Service is a generic interface for storage backends

Jump to

Keyboard shortcuts

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