s3fs

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 18 Imported by: 0 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

github.com/jarxorg/s3fs

PkgGoDev Report Card

Package s3fs provides an implementation of wfs for S3.

Examples

ReadDir
package main

import (
  "fmt"
  "io/fs"
  "log"

  "github.com/jarxorg/s3fs"
)

func main() {
  fsys := s3fs.New("<your-bucket>")
  entries, err := fs.ReadDir(fsys, ".")
  if err != nil {
    log.Fatal(err)
  }
  for _, entry := range entries {
    fmt.Println(entry.Name())
  }
}
WriteFile
package main

import (
  "io/fs"
  "log"

  "github.com/jarxorg/wfs"
  "github.com/jarxorg/s3fs"
)

func main() {
  fsys := s3fs.New("<your-bucket>")
  _, err := wfs.WriteFile(fsys, "test.txt", []byte(`Hello`), fs.ModePerm)
  if err != nil {
    log.Fatal(err)
  }
}

Tests

S3FS can pass TestFS in "testing/fstest".

import (
  "testing/fstest"
  "github.com/jarxorg/s3fs"
)

// ...

fsys := s3fs.New("<your-bucket>")
if err := fstest.TestFS(fsys, "<your-expected>"); err != nil {
  t.Errorf("Error testing/fstest: %+v", err)
}

Integration tests

FSTEST_BUCKET="<your-bucket>" \
FSTEST_EXPECTED="<your-expected>" \
  go test -tags integtest ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type S3FS

type S3FS struct {
	// DirOpenBufferSize is the buffer size for using objects as the directory. (Default 100)
	DirOpenBufferSize int
	// ListBufferSize is the buffer size for listing objects that is used on
	// ReadDir, Glob and RemoveAll. (Default 1000)
	ListBufferSize int
	// contains filtered or unexported fields
}

S3FS represents a filesystem on S3 (Amazon Simple Storage Service).

func New

func New(bucket string) *S3FS

New returns a filesystem for the tree of objects rooted at the specified bucket. This function is the same as the following code.

NewWithSession(bucket, session.Must(
  session.NewSessionWithOptions(
    session.Options{SharedConfigState: session.SharedConfigEnable}
  )
))

func NewWithAPI

func NewWithAPI(bucket string, api s3iface.S3API) *S3FS

NewWithAPI returns a filesystem for the tree of objects rooted at the specified bucket with the s3 client.

func NewWithSession

func NewWithSession(bucket string, sess *session.Session) *S3FS

NewWithSession returns a filesystem for the tree of objects rooted at the specified bucket with the session.

func (*S3FS) CreateFile

func (fsys *S3FS) CreateFile(name string, mode fs.FileMode) (wfs.WriterFile, error)

CreateFile creates the named file. The specified mode is ignored.

func (*S3FS) Glob

func (fsys *S3FS) Glob(pattern string) ([]string, error)

Glob returns the names of all files matching pattern, providing an implementation of the top-level Glob function.

func (*S3FS) MkdirAll

func (fsys *S3FS) MkdirAll(dir string, mode fs.FileMode) error

MkdirAll always do nothing.

func (*S3FS) Open

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

Open opens the named file or directory.

func (*S3FS) ReadDir

func (fsys *S3FS) ReadDir(dir string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries sorted by filename.

func (*S3FS) ReadFile

func (fsys *S3FS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents.

func (*S3FS) RemoveAll

func (fsys *S3FS) RemoveAll(dir string) error

RemoveAll removes path and any children it contains.

func (*S3FS) RemoveFile

func (fsys *S3FS) RemoveFile(name string) error

RemoveFile removes the specified named file.

func (*S3FS) Stat

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

Stat returns a FileInfo describing the file. If there is an error, it should be of type *PathError.

func (*S3FS) Sub

func (fsys *S3FS) Sub(dir string) (fs.FS, error)

Sub returns an FS corresponding to the subtree rooted at dir.

func (*S3FS) WriteFile

func (fsys *S3FS) WriteFile(name string, p []byte, mode fs.FileMode) (int, error)

WriteFile writes the specified bytes to the named file. The specified mode is ignored.

Jump to

Keyboard shortcuts

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