s3fs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT, MIT Imports: 22 Imported by: 0

README

s3fs

created by Austin Poor

An implementation of the go-billy Filesystem for treating an S3 bucket like a filesystem.

Documentation

Index

Constants

View Source
const (
	O_RDONLY      int = os.O_RDONLY // open the file read-only.
	O_WRONLY      int = os.O_WRONLY // open the file write-only.
	O_WRMULTIPART int = 0x4         // open the file for write-only using multipart upload.

	SupportedOFlags = O_RDONLY | O_WRONLY | O_WRMULTIPART // supported open flags for s3fs
)
View Source
const (
	DefaultSeparator = "/"
)
View Source
const (
	ModeMultipartUpload os.FileMode = fs.ModePerm + 1 // Custom os.FileMode for S3 multipart upload
)

Variables

View Source
var (
	ErrNotImplemented        = errors.New("not implemented")
	ErrLockNotSupported      = errors.New("lock not supported by s3")
	ErrTruncateNotSupported  = errors.New("truncate not supported by s3")
	ErrFileClosed            = errors.New("file is closed")
	ErrCantWriteToReadOnly   = errors.New("can't write to read-only file")
	ErrCantReadFromWriteOnly = errors.New("can't read from write-only file")
)
View Source
var (
	ErrOpenFlagNotSupported = errors.New("open flag not supported")
)
View Source
var (
	ErrSymLinkNotSupported = errors.New("symlink not supported by s3")
)

Functions

func NewS3FS

func NewS3FS(client *storage.Client, bucket string, opts ...Option) (billy.Filesystem, error)

NewS3FS creates a new S3FS Filesystem.

Types

type FileStat

type FileStat struct {
	UID, GID uint32
}

FileStat is the value returned by simpleFileInfo.Sys() when the Unix-metadata feature is enabled. It carries the raw numeric owner and group so consumers can resolve them to names however they like.

type Option

type Option func(*S3FS)

Option configures an S3FS at construction time.

func WithUnixMetadata

func WithUnixMetadata(uid, gid uint32, umask os.FileMode) Option

WithUnixMetadata enables storing and reading POSIX file attributes as S3 user metadata (see the unixmeta package). uid and gid are the numeric owner/group recorded on newly written objects; callers resolve any names to numbers themselves. umask is applied to the default mode (0666 for files) when writing. Without this option the filesystem stores no attributes.

type S3FS

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

func (*S3FS) Capabilities

func (fs3 *S3FS) Capabilities() billy.Capability

Capabilities returns the filesystem capabilities.

func (*S3FS) Chroot

func (fs3 *S3FS) Chroot(path string) (billy.Filesystem, error)

Chroot returns a new filesystem from the same type where the new root is the given path. Files outside of the designated directory tree cannot be accessed.

func (*S3FS) Create

func (fs3 *S3FS) Create(filename string) (billy.File, error)

Create implements billy.Basic Create creates the named file with mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.

func (*S3FS) Join

func (fs3 *S3FS) Join(elem ...string) string

Join joins any number of path elements into a single path

func (*S3FS) Lstat

func (fs3 *S3FS) Lstat(filename string) (os.FileInfo, error)

Lstat returns a FileInfo describing the named file. S3 has no symlinks, so Lstat is equivalent to Stat. We still implement it so callers that type-assert billy.Symlink (rm, du, cp, ls, touch, file, billyfs, billysh) get a usable FileInfo instead of ErrSymLinkNotSupported.

func (*S3FS) MkdirAll

func (fs3 *S3FS) MkdirAll(filename string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is/ already a directory, MkdirAll does nothing and returns nil.

func (*S3FS) Open

func (fs3 *S3FS) Open(filename string) (billy.File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.

func (*S3FS) OpenFile

func (fs3 *S3FS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O.

func (*S3FS) ReadDir

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

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

func (fs3 *S3FS) Readlink(link string) (string, error)

Readlink returns the target path of link.

NOTE: Readlink is not supported by s3. It always returns an error. (This may be revised in the future.)

func (*S3FS) Remove

func (fs3 *S3FS) Remove(filename string) error

Remove removes the named file or directory. In-memory TempFile entries are dropped from the registry without an S3 call.

func (*S3FS) Rename

func (fs3 *S3FS) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath. If oldpath refers to an in-memory TempFile, its buffer is uploaded to S3 under newpath and the registry entry is dropped — this is how PackWriter's "tmp_pack_… → pack-<sha>.pack" promotion lands the final pack in the bucket. Otherwise Rename uses Tigris's in-place RenameObject extension.

func (*S3FS) Root

func (fs3 *S3FS) Root() string

Root returns the root path of the filesystem.

func (*S3FS) Stat

func (fs3 *S3FS) Stat(filename string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file.

func (fs3 *S3FS) Symlink(target, link string) error

Symlink creates a symbolic-link from link to target. target may be an absolute or relative path, and need not refer to an existing node. Parent directories of link are created as necessary.

NOTE: Symlink is not supported by s3. It always returns an error.

func (*S3FS) TempFile

func (fs3 *S3FS) TempFile(dir, prefix string) (billy.File, error)

TempFile creates a uniquely named file under dir whose name begins with prefix and returns a write handle to it. The bytes live in an in-memory buffer registered against the filesystem; a subsequent Open of the same path returns a reader over that same buffer (needed by go-git's streaming PackWriter, which reads the temp pack back as it is written). The buffer is uploaded to S3 only when the caller renames the path to its final location; Remove discards it.

Directories

Path Synopsis
Package unixmeta encodes and decodes POSIX file attributes (owner, group, permissions, timestamps) as S3 user-defined metadata (x-amz-meta-* headers).
Package unixmeta encodes and decodes POSIX file attributes (owner, group, permissions, timestamps) as S3 user-defined metadata (x-amz-meta-* headers).

Jump to

Keyboard shortcuts

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