files

package
v1.2.97 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineUri

func CombineUri(uri string, parts ...string) string

CombineUri creates a URI from segments

func GetUriPath

func GetUriPath(uri string) (path string, err error)

GetUriPath extract path from the uri

func ParseUri

func ParseUri(uri string) (schema, path, file, ext string, err error)

ParseUri decompose URI to parts

Types

type HttpFile

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

HttpFile is a concrete http implementation of IFile interface

func (*HttpFile) Close

func (f *HttpFile) Close() error

Close release the file resource

func (*HttpFile) Copy

func (f *HttpFile) Copy(wc io.WriteCloser) (int64, error)

Copy file content to a writer

func (*HttpFile) Delete

func (f *HttpFile) Delete() error

Delete resource

func (*HttpFile) Exists

func (f *HttpFile) Exists() (result bool)

Exists test for resource existence

func (*HttpFile) Read

func (f *HttpFile) Read(p []byte) (int, error)

Read implements io.Reader interface

func (*HttpFile) ReadAll

func (f *HttpFile) ReadAll() ([]byte, error)

ReadAll read resource content to a byte array in a single call

func (*HttpFile) Rename

func (f *HttpFile) Rename(pattern string) (string, error)

Rename change the resource name using pattern. The pattern can be a file or keeping parts from the original file using template ({{path}}, {{file}}, {{ext}})

func (*HttpFile) URI

func (f *HttpFile) URI() string

URI returns the resource URI with schema Schema can be: file, gcs, http etc

func (*HttpFile) Write

func (f *HttpFile) Write(p []byte) (int, error)

Write implements io.Writer interface

func (*HttpFile) WriteAll

func (f *HttpFile) WriteAll(b []byte) (int, error)

WriteAll write content to a resource in a single call

type HttpFileStore

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

HttpFileStore is a concrete implementation of FileStore interface

func (*HttpFileStore) Apply

func (f *HttpFileStore) Apply(filter string, action func(string)) error

Apply action on files in the file store

func (*HttpFileStore) Delete

func (f *HttpFileStore) Delete(uri string) (err error)

Delete resource

func (*HttpFileStore) Exists

func (f *HttpFileStore) Exists(uri string) (result bool)

Exists test for resource existence

func (*HttpFileStore) List

func (f *HttpFileStore) List(filter string) ([]IFile, error)

List files in the file store

func (*HttpFileStore) URI

func (f *HttpFileStore) URI() string

URI returns the resource URI with schema

type IFile

type IFile interface {

	// ReadWriteCloser must implement Read(), Write() and Close() method
	io.ReadWriteCloser

	// URI returns the resource URI with schema
	// Schema can be: file, gcs, http etc
	URI() string

	// Exists test for resource existence
	Exists() (result bool)

	// Rename change the resource name using pattern.
	// The pattern can be an absolute name or keeping parts from the original file using template (path, name, ext)
	Rename(pattern string) (result string, err error)

	// Delete resource
	Delete() (err error)

	// ReadAll read resource content to a byte array in a single call
	ReadAll() (b []byte, err error)

	// WriteAll write content to a resource in a single call
	WriteAll(b []byte) (n int, err error)

	// Copy file content to a writer
	Copy(wc io.WriteCloser) (written int64, err error)
}

IFile File interface This interface is used for concrete implementation of any file (local file system, HTTP files, Google / AWS Buckets etc).

func NewHttpFile

func NewHttpFile(uri string) IFile

NewHttpFile factory method

func NewLocalFile

func NewLocalFile(uri string) IFile

NewLocalFile factory method

type IFileStore

type IFileStore interface {

	// URI returns the resource URI with schema
	// Schema can be: file, gcs, http etc
	URI() string

	// List files in the URI using regexp filter
	List(filter string) (result []IFile, err error)

	// Apply action on files in the file store
	Apply(filter string, action func(string)) error

	// Exists test for resource existence
	Exists(uri string) (result bool)

	// Delete resource
	Delete(uri string) (err error)
}

IFileStore Files store interface This interface is used for concrete implementation of any file store (local file system, HTTP files, Google / AWS Buckets etc.

func NewHttpFileStore

func NewHttpFileStore(uri string) IFileStore

NewHttpFileStore factory method

func NewLocalFileStore

func NewLocalFileStore(uri string) IFileStore

NewLocalFileStore factory method

type LocalFile

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

LocalFile is a concrete file system implementation of IFile interface

func (*LocalFile) Close

func (f *LocalFile) Close() error

Close release the file resource

func (*LocalFile) Copy

func (f *LocalFile) Copy(wc io.WriteCloser) (int64, error)

Copy file content to a writer

func (*LocalFile) Delete

func (f *LocalFile) Delete() error

Delete resource

func (*LocalFile) Exists

func (f *LocalFile) Exists() (result bool)

Exists test for resource existence

func (*LocalFile) Read

func (f *LocalFile) Read(p []byte) (int, error)

Read implements io.Reader interface

func (*LocalFile) ReadAll

func (f *LocalFile) ReadAll() ([]byte, error)

ReadAll read resource content to a byte array in a single call

func (*LocalFile) Rename

func (f *LocalFile) Rename(pattern string) (string, error)

Rename change the resource name using pattern. The pattern can be a file or keeping parts from the original file using template ({{path}}, {{file}}, {{ext}})

func (*LocalFile) URI

func (f *LocalFile) URI() string

URI returns the resource URI with schema Schema can be: file, gcs, http etc

func (*LocalFile) Write

func (f *LocalFile) Write(p []byte) (int, error)

Write implements io.Writer interface

func (*LocalFile) WriteAll

func (f *LocalFile) WriteAll(b []byte) (int, error)

WriteAll write content to a resource in a single call

type LocalFileStore

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

LocalFileStore is a concrete implementation of FileStore interface

func (*LocalFileStore) Apply

func (f *LocalFileStore) Apply(filter string, action func(string)) error

Apply action on files in the file store

func (*LocalFileStore) Delete

func (f *LocalFileStore) Delete(uri string) (err error)

Delete resource

func (*LocalFileStore) Exists

func (f *LocalFileStore) Exists(uri string) (result bool)

Exists test for resource existence

func (*LocalFileStore) List

func (f *LocalFileStore) List(filter string) ([]IFile, error)

List files in the file store

func (*LocalFileStore) URI

func (f *LocalFileStore) URI() string

URI returns the resource URI with schema Schema can be: file, gcs, http etc

Jump to

Keyboard shortcuts

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