github.com/goravel/framework@v1.13.9/contracts/filesystem/storage.go (about)

     1  package filesystem
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  )
     7  
     8  //go:generate mockery --name=Storage
     9  type Storage interface {
    10  	Driver
    11  	// Disk gets the instance of the given disk.
    12  	Disk(disk string) Driver
    13  }
    14  
    15  //go:generate mockery --name=Driver
    16  type Driver interface {
    17  	// AllDirectories gets all the directories within a given directory(recursive).
    18  	AllDirectories(path string) ([]string, error)
    19  	// AllFiles gets all the files from the given directory(recursive).
    20  	AllFiles(path string) ([]string, error)
    21  	// Copy the given file to a new location.
    22  	Copy(oldFile, newFile string) error
    23  	// Delete deletes the given file(s).
    24  	Delete(file ...string) error
    25  	// DeleteDirectory deletes the given directory(recursive).
    26  	DeleteDirectory(directory string) error
    27  	// Directories get all the directories within a given directory.
    28  	Directories(path string) ([]string, error)
    29  	// Exists determines if a file exists.
    30  	Exists(file string) bool
    31  	// Files gets all the files from the given directory.
    32  	Files(path string) ([]string, error)
    33  	// Get gets the contents of a file.
    34  	Get(file string) (string, error)
    35  	// GetBytes gets the contents of a file as a byte array.
    36  	GetBytes(file string) ([]byte, error)
    37  	// LastModified gets the file's last modified time.
    38  	LastModified(file string) (time.Time, error)
    39  	// MakeDirectory creates a directory.
    40  	MakeDirectory(directory string) error
    41  	// MimeType gets the file's mime type.
    42  	MimeType(file string) (string, error)
    43  	// Missing determines if a file is missing.
    44  	Missing(file string) bool
    45  	// Move a file to a new location.
    46  	Move(oldFile, newFile string) error
    47  	// Path gets the full path for the file.
    48  	Path(file string) string
    49  	// Put writes the contents of a file.
    50  	Put(file, content string) error
    51  	// PutFile upload the given file.
    52  	PutFile(path string, source File) (string, error)
    53  	// PutFileAs upload the given file with a new name.
    54  	PutFileAs(path string, source File, name string) (string, error)
    55  	// Size gets the file size of a given file.
    56  	Size(file string) (int64, error)
    57  	// TemporaryUrl get a temporary URL for the file.
    58  	TemporaryUrl(file string, time time.Time) (string, error)
    59  	// WithContext sets the context to be used by the driver.
    60  	WithContext(ctx context.Context) Driver
    61  	// Url get the URL for the file at the given path.
    62  	Url(file string) string
    63  }
    64  
    65  //go:generate mockery --name=File
    66  type File interface {
    67  	// Disk gets the instance of the given disk.
    68  	Disk(disk string) File
    69  	// Extension gets the file extension.
    70  	Extension() (string, error)
    71  	// File gets the file path.
    72  	File() string
    73  	// GetClientOriginalName gets the client original name.
    74  	GetClientOriginalName() string
    75  	// GetClientOriginalExtension gets the client original extension.
    76  	GetClientOriginalExtension() string
    77  	// HashName gets the file's hash name.
    78  	HashName(path ...string) string
    79  	// LastModified gets the file's last modified time.
    80  	LastModified() (time.Time, error)
    81  	// MimeType gets the file's mime type.
    82  	MimeType() (string, error)
    83  	// Size gets the file size.
    84  	Size() (int64, error)
    85  	// Store the file at the given path.
    86  	Store(path string) (string, error)
    87  	// StoreAs store the file at the given path with a new name.
    88  	StoreAs(path string, name string) (string, error)
    89  }