af3ro

package module
v0.0.0-...-b2bb697 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

README

af3ro - afero-compatible interface to S3

Will check etags when writing a file to avoid writing files that don't need to be overwritten (etags are MD5 sums of file contents)

For more information about afero see the github page.

package foo

import (
    "github.com/goamz/goamz/aws"
    "github.com/ryansb/af3ro"
    "github.com/spf13/afero"
)


var s3fs afero.Fs = af3ro.NewS3Fs(af3ro.Bucket("some.bucket.name"), af3ro.Region(aws.USEast), af3ro.EnvAuth())

Caveats

Don't use this for big files for these reasons:

  • Files are stored in memory until being written to S3 so you can OOM your program.
  • Multipart uploads aren't supported, full file contents are uploaded in one PUT request.
  • Etags for multipart files aren't supported and will fail, causing files uploaded initially as multipart to always be re-uploaded.

Data is only written to S3 when a file is closed so be aware that failing to close a file means it won't be written.

Permissions are translated from os.FileMode to AWS S3 ACLs, which are less expressive and don't completely map to FileModes, so double-check that the correct permissions are set in S3

Basically, this is for small files where you (for some reason) aren't able to use the goamz/s3 library directly and have to present a local-like filesystem interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryFile

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

func MemFileCreate

func MemFileCreate(name string, bucket *s3.Bucket) *InMemoryFile

func (*InMemoryFile) Close

func (f *InMemoryFile) Close() (err error)

func (*InMemoryFile) Info

func (f *InMemoryFile) Info() *InMemoryFileInfo

func (*InMemoryFile) Name

func (f *InMemoryFile) Name() string

func (*InMemoryFile) Open

func (f *InMemoryFile) Open() error

func (*InMemoryFile) Read

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

func (*InMemoryFile) ReadAt

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

func (*InMemoryFile) Readdir

func (f *InMemoryFile) Readdir(count int) (res []os.FileInfo, err error)

func (*InMemoryFile) Readdirnames

func (f *InMemoryFile) Readdirnames(n int) (names []string, err error)

func (*InMemoryFile) Seek

func (f *InMemoryFile) Seek(offset int64, whence int) (int64, error)

func (*InMemoryFile) Stat

func (f *InMemoryFile) Stat() (os.FileInfo, error)

func (*InMemoryFile) Sync

func (f *InMemoryFile) Sync() error

func (*InMemoryFile) Truncate

func (f *InMemoryFile) Truncate(size int64) error

func (*InMemoryFile) Write

func (f *InMemoryFile) Write(b []byte) (n int, err error)

func (*InMemoryFile) WriteAt

func (f *InMemoryFile) WriteAt(b []byte, off int64) (n int, err error)

func (*InMemoryFile) WriteString

func (f *InMemoryFile) WriteString(s string) (ret int, err error)

type InMemoryFileInfo

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

func (*InMemoryFileInfo) IsDir

func (s *InMemoryFileInfo) IsDir() bool

func (*InMemoryFileInfo) ModTime

func (s *InMemoryFileInfo) ModTime() time.Time

func (*InMemoryFileInfo) Mode

func (s *InMemoryFileInfo) Mode() os.FileMode

func (*InMemoryFileInfo) Name

func (s *InMemoryFileInfo) Name() string

Implements os.FileInfo

func (*InMemoryFileInfo) Size

func (s *InMemoryFileInfo) Size() int64

func (*InMemoryFileInfo) Sys

func (s *InMemoryFileInfo) Sys() interface{}

type MemDir

type MemDir interface {
	Len() int
	Names() []string
	Files() []afero.File
	Add(afero.File)
	Remove(afero.File)
}

type MemDirMap

type MemDirMap map[string]afero.File

func (MemDirMap) Add

func (m MemDirMap) Add(f afero.File)

func (MemDirMap) Files

func (m MemDirMap) Files() (files []afero.File)

func (MemDirMap) Len

func (m MemDirMap) Len() int

func (MemDirMap) Names

func (m MemDirMap) Names() (names []string)

func (MemDirMap) Remove

func (m MemDirMap) Remove(f afero.File)

type MemS3Fs

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

func NewS3Fs

func NewS3Fs(options ...Option) *MemS3Fs

func S3FsFromBucket

func S3FsFromBucket(b s3.Bucket) *MemS3Fs

func (*MemS3Fs) Chmod

func (m *MemS3Fs) Chmod(name string, mode os.FileMode) error

func (*MemS3Fs) Chtimes

func (m *MemS3Fs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*MemS3Fs) Create

func (m *MemS3Fs) Create(name string) (afero.File, error)

func (*MemS3Fs) List

func (m *MemS3Fs) List()

func (*MemS3Fs) Mkdir

func (m *MemS3Fs) Mkdir(name string, perm os.FileMode) error

Mkdir doesn't actually save anything to S3 unless they have contents. The cloud doesn't have directories.

func (*MemS3Fs) MkdirAll

func (m *MemS3Fs) MkdirAll(path string, perm os.FileMode) error

MkdirAll doesn't actually save anything to S3 unless they have contents. The cloud doesn't have directories.

func (MemS3Fs) Name

func (MemS3Fs) Name() string

func (*MemS3Fs) Open

func (m *MemS3Fs) Open(name string) (afero.File, error)

func (*MemS3Fs) OpenFile

func (m *MemS3Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile ignores the `flag` argument but respects `perm`

func (*MemS3Fs) Remove

func (m *MemS3Fs) Remove(name string) error

Removes file immediately from both S3 and the local cache

func (*MemS3Fs) RemoveAll

func (m *MemS3Fs) RemoveAll(path string) error

func (*MemS3Fs) Rename

func (m *MemS3Fs) Rename(oldname, newname string) error

func (*MemS3Fs) Stat

func (m *MemS3Fs) Stat(name string) (os.FileInfo, error)

type Option

type Option func(*MemS3Fs)

func Auth

func Auth(auth aws.Auth) Option

func Bucket

func Bucket(name string) Option

func EnvAuth

func EnvAuth() Option

func Region

func Region(region aws.Region) Option

type PermU

type PermU uint

Jump to

Keyboard shortcuts

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