s3iofs

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

README

s3iofs Go Report Card Documentation

This package provides an S3 implementation for Go1.16 filesystem interface.

Overview

This package provides an S3 implementation for the Go1.16 filesystem interface using the AWS SDK for Go v2.

The S3FS implements the following interfaces:

  • fs.FS
  • fs.StatFS
  • fs.ReadDirFS

The s3File implements the following interfaces:

  • fs.FileInfo
  • fs.DirEntry
  • io.ReaderAt
  • io.Seeker

In addition to this the S3FS also implements the following interfaces:

  • RemoveFS, which provides a Remove(name string) error method.
  • WriteFileFS which provides a WriteFile(name string, data []byte, perm fs.FileMode) error method.

This enables libraries such as apache arrow to read parts of a parquet file from S3, without downloading the entire file.

Usage

	// Load the Shared AWS Configuration (~/.aws/config) and enable request logging
	awscfg, err := config.LoadDefaultConfig(context.TODO(),
		config.WithClientLogMode(aws.LogRetries|aws.LogRequest),
		config.WithLogger(logging.NewStandardLogger(os.Stdout)),
	)
	if err != nil {
		// ...
	}

	s3fs := s3iofs.New(os.Getenv("TEST_BUCKET_NAME"), awscfg)

	err = fs.WalkDir(s3fs, ".", func(path string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}

		if d.IsDir() {
			fmt.Println("dir:", path)
			return nil
		}
		fmt.Println("file:", path)
		return nil
	})
	if err != nil {
		// ...
	}

Integration Tests

The integration tests for this package are in a separate module under the integration directory, this to avoid polluting the main module with docker based testing dependencies used to run the tests locally against minio.

S3 implements ranges based on HTTP Request ranges, it well worth reading up on this if your using the io.ReadSeek interface.

License

This application is released under Apache 2.0 license and is copyright Mark Wolfe.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RemoveFS added in v1.5.1

type RemoveFS interface {
	fs.FS
	Remove(name string) error
}

RemoveFS extend the fs.FS interface to add the Remove method.

type S3API

type S3API interface {
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
	HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
	DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
}

S3API s3 calls used to build this library, this is used to enable testing.

type S3FS

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

S3FS is a filesystem implementation using S3.

func New

func New(bucket string, awscfg aws.Config) *S3FS

New returns a new filesystem which provides access to the specified s3 bucket.

func NewWithClient added in v1.1.0

func NewWithClient(bucket string, client S3API) *S3FS

NewWithClient returns a new filesystem which provides access to the specified s3 bucket.

func (*S3FS) Open

func (s3fs *S3FS) Open(name string) (fs.File, error)

Open opens the named file.

func (*S3FS) ReadDir

func (s3fs *S3FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory.

func (*S3FS) Remove added in v1.5.1

func (s3fs *S3FS) Remove(name string) error

Remove removes the named file or directory.

Note if the file doesn't exist in the s3 bucket, Remove returns nil.

func (*S3FS) Stat

func (s3fs *S3FS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the file.

func (*S3FS) WriteFile added in v1.5.2

func (s3fs *S3FS) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes the data to the named file in s3.

Note:

  • If the file exists, WriteFile overwrites it.
  • The provided mode is unused by this implementation.

type WriteFileFS added in v1.5.2

type WriteFileFS interface {
	fs.FS
	WriteFile(name string, data []byte, perm os.FileMode) error
}

WriteFileFS extend the fs.FS interface to add the WriteFile method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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