file

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: Apache-2.0 Imports: 12 Imported by: 73

README

file - file storage

This package provides a file system manager that wraps os operations.

Usage
func main() {
	service := afs.New()
	ctx := context.Background()
	err := service.Upload(ctx, "file:///folder1/asset.txt", 0644, strings.NewReader("some content"))
	if err != nil {
		log.Fatal(err)
	}
	objects, err := service.List(ctx, "file:///folder1/")
	if err != nil {
		log.Fatal(err)
	}
	for _, object := range objects {
		fmt.Printf("%v %v\n", object.URL(), object.Name())
	}
}

Documentation

Overview

Package file defines a file system storage

Index

Constants

View Source
const (
	//DefaultDirOsMode folder mode default
	DefaultDirOsMode = os.ModeDir | 0755
	//DefaultFileOsMode file mode default
	DefaultFileOsMode = os.FileMode(0644)
)
View Source
const Scheme = "file"

Scheme file URL scheme

Variables

This section is empty.

Functions

func AdjustInfoSize

func AdjustInfoSize(info os.FileInfo, size int) os.FileInfo

AdjustInfoSize adjust file info size

func Create

func Create(ctx context.Context, URL string, mode os.FileMode, isDir bool, options ...storage.Option) error

Create creates a new file or directory

func Delete

func Delete(ctx context.Context, URL string, options ...storage.Option) error

Delete removes file or directory

func Download

func Download(ctx context.Context, object storage.Object, options ...storage.Option) (io.ReadCloser, error)

Download downloads TestContent for the supplied object

func DownloadWithURL

func DownloadWithURL(ctx context.Context, URL string, options ...storage.Option) (io.ReadCloser, error)

DownloadWithURL downloads content for the supplied object

func EnsureParentPathExists

func EnsureParentPathExists(filename string, fileMode os.FileMode) error

EnsureParentPathExists create parent path if needed

func List

func List(ctx context.Context, URL string, options ...storage.Option) ([]storage.Object, error)

List list directory or returns a file Info

func Mode

func Mode(info os.FileInfo) os.FileMode

Mode returns mode for file Info

func Move

func Move(ctx context.Context, sourceURL, destURL string, options ...storage.Option) error

Move moves source to URL

func New

func New() storage.Manager

New returns a file manager

func NewInfo

func NewInfo(name string, size int64, mode os.FileMode, modificationTime time.Time, isDir bool, options ...storage.Option) os.FileInfo

NewInfo returns a ew file Info

func NewMode

func NewMode(attributes string) (os.FileMode, error)

NewMode returns a new file mode for supplied attributes

func Path

func Path(location string) string

Path returns shortest path for specified location, if relative it adds current directory

func Provider

func Provider(options ...storage.Option) (storage.Manager, error)

Provider provider function

func Upload

func Upload(ctx context.Context, URL string, mode os.FileMode, reader io.Reader, options ...storage.Option) error

Upload writes reader content to supplied URL path.

Types

type Info

type Info struct {
	*object.Link
	// contains filtered or unexported fields
}

Info represents a file info

func (*Info) IsDir

func (i *Info) IsDir() bool

IsDir returns true if resoruce is directory

func (*Info) ModTime

func (i *Info) ModTime() time.Time

ModTime returns modification time

func (*Info) Mode

func (i *Info) Mode() os.FileMode

Mode returns file mode

func (*Info) Name

func (i *Info) Name() string

Name returns a name

func (*Info) Size

func (i *Info) Size() int64

Size returns file size

func (*Info) Sys

func (i *Info) Sys() interface{}

Sys returns sys object

Jump to

Keyboard shortcuts

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